-
Notifications
You must be signed in to change notification settings - Fork 219
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
If onInit get called many times, where to fetch data #104
Comments
Hey there -- in general, any time you see a Stateful Widget running To fix this issue, you can assign a Could you please try assigning a Key to the StoreConnector and seeing if it solves the problem? If not, please provide a small code sample that demonstrates the issue! |
Hi, thanks for the reply, I tried to assign a key in the Navigator.push(context, MaterialPageRoute(builder: (context) {
/// This get called many times
return MyOtherPage();
})); I'm not sure if this is related to I will try to provide a minimal working code asap. Thanks again. |
Ah, yes -- the Widget tree can be rebuilt at any time. However, StatefulWidgets are meant to be rebuilt, especially if you have a key there. I'll take a look and see what might be causing the issue, if you happen to reproduce with a small sample that'd be great because I haven't had that problem and have some tests to ensure it doesn't happen, but there could definitely be a mistake / bug / unhandled case in there. |
Hi, I'm sorry for the late reply. After a more detailed debugging, I found that the problem is that I share some of the loading state between different screens (not a very good way to do this) and some how they are still alive behind the current screen even after I pop it some how and when the current screen state changes, it also affected the other screens and trigger the routing action, and hence everything is rebuilt and |
It's a mistake I've made before as well :) In that case, I'll go ahead and close this one out since I couldn't find anything wrong and have tests covering this case. |
@panuavakul I seem to be having a very similar problem to this right now... if you don't mind, I would very much appreciate some details on how you ended up fixing this? |
Hi according to the
StoreConnector
'sonInit
So I'm assuming that I should dispatch some action here to fetch data from API and initialized my widget. However, there are many times that when the widget is rebuild, the StoreConnector is also rebuilt and the onInit is called, namely when focusing and unfocusing on
TextFormField
, which cause theonInit
to be called multiple times resulting in unwanted API call.This seems to be Flutter intended behaviour. flutter/flutter#14124
So I'm wondering how is everyone dealing with this problem?
Thanks
The text was updated successfully, but these errors were encountered: