Graphql-flutter: FetchMore disposes and recreates child widget of Query

Created on 7 Jan 2020  路  6Comments  路  Source: zino-app/graphql-flutter

Describe the bug
I have a stateless widget that builds a Query widget, the builder method of which returns a stateful widget. The widget structure is: Stateless -> Query -> Stateful. I pass fetchMore from the Query widget to the stateful widget. The stateful widget then calls fetchMore when going to the next page. When fetchMore is called, the initState of the stateful widget is also called. It seems like the stateful widget is getting disposed and recreated by the Query builder.

To Reproduce
Steps to reproduce the behavior:

  1. Create a stateless widget
  2. Create a stateful widget, add a print statement in the initState hook
  3. In the build method of the stateless widget, return the graphql Query widget, in the builder method, return the stateful widget and pass fetchMore into it.
  4. Call fetchMore from the stateful widget. See that the print statement from initState is executed.

Expected behavior
Fetching more does not dispose and recreate the child widget. It just updates the props.

Desktop (please complete the following information):

  • OS: MacOS Catalina

Smartphone (please complete the following information):

  • Device: iPhone 11
  • OS: iOS 12
bug flutter outdated released released on @beta

Most helpful comment

Okay, that makes sense. You can try and lift the state up for now as we find a solution to this. I will investigate further.

All 6 comments

If I am getting what you said correctly if the Query is the one building the Stateful widget, then the rebuild of the stateful widget is almost expected. Whenever fetchmore is called, you are explicitly saying you want the previous results and new results to be merged. When the new data arrives, it is merged behind the scenes, the stream is updated with data containing both results as one and this is what triggers a rebuild.

@mainawycliffe thank you for the reply. Yes, I do expect a rebuild but that doesn't look like what is happening. I would expect the stateful widget to fire didUpdateWidget, rather than initState. This means that whenever I want to fetchMore, any state I was maintaining in the stateful widget is now lost. For example, if my stateful widget was a counter widget that fetched more on every 5 counts, it would reset to 0 with every fetchMore instead of fetching at 5, 10, 15, and so on. Is there a way around this?

Okay, that makes sense. You can try and lift the state up for now as we find a solution to this. I will investigate further.

@mainawycliffe @KevinShiCA any solution did you find?

:tada: This issue has been resolved in version 4.0.0-beta.3 :tada:

The release is available on GitHub release

Your semantic-release bot :package::rocket:

:tada: This issue has been resolved in version 4.0.0 :tada:

The release is available on GitHub release

Your semantic-release bot :package::rocket:

Was this page helpful?
0 / 5 - 0 ratings

Related issues

milind-solutelabs picture milind-solutelabs  路  3Comments

micimize picture micimize  路  4Comments

micimize picture micimize  路  3Comments

juicycleff picture juicycleff  路  4Comments

javi11 picture javi11  路  3Comments