Closed jonasbark closed 3 years ago
Thanks to @SunlightBro I understood it's due to the fact that the store is recreated as it's not a static field (like in the official samples). It still leaves me thinking why it worked with e.g. 3.0.5.
In my app, I'd like to work with independent stores that do not share data. The store could even be dynamically created e.g. when opening a detail page so I wouldn't want to store a reference to it in a field.
For now I'm storing it in a field and resetting in in the initState of the widget that contains the StoreProvider. So the question really is: How do I handle multiple and even dynamically created stores?
You can't create the store inside of the build
method, otherwise it will create a new store each time the build method is called. Flutter calls build
methods all the time. You shouldn't use it to create state, no matter the state management solution you use. It's even worse if it's in a StatelessWidget
.
I guess you can save the store into a field of the State
of a StatefulWidget
.
I have no idea why it worked in such an old version.
Also, I suggest you call the state AppState
, not AppStore
.
Hi there,
Today I upgraded from 3.0.5 to 9.0.0 - so far a seamless experience until I tried hot reload. It seems that the state is lost and calls to e.g. onInit are no longer happening.
I could narrow it down to this simple example:
Expected:
I double checked - it works as expected in 3.0.5.
Edit: Following observation:
Which leaves me thinking that the onInit 'issue' is expected behavior, yet I don't understand why the state is lost.