brianegan / flutter_redux

A library that connects Widgets to a Redux Store
MIT License
1.65k stars 219 forks source link

Disconnect from redux store during debugging #204

Closed mjlorenzo closed 3 years ago

mjlorenzo commented 3 years ago

I'm encountering a strange issue during debugging with Android Studio: My tree hierarchy begins typically: MyApp -> StoreProvider -> MaterialApp -> etc.. The StoreProvider widget is provided a store object with an initialState consisting of empty sets, lists, etc.. (no actual data, just the skeleton). My app then populates the state by requesting web data and dispatching actions with the responses, all standard stuff. On the very first run of the app in debug mode (with the IDE debugger attached for breakpoints and whatnot), everything is fine. If any of these three events occurs, things get weird:

  1. I 'Hot Restart' the application
  2. The Android back button is pressed on the only page in the root Navigator
  3. I explicitly call SystemNavigator.pop() (I think #2 implicitly does this?)

After re-entering the app, the redux store is disconnected somehow. The same initialization code executes and if I step-debug that code I see the store's internal _state object correctly reflecting dispatch() calls, but the state object the rest of the application irreversibly now sees is the 'blank' object I passed in the initialState parameter. My AppState constructor does not contain these default values, so it must be the same object. Again, this disjunction does not occur before one of the above events occurs. Even stranger, if I disconnect the IDE debugger and restart the app, events 2 and 3 are no longer an issue. I can freely back out of the app or take actions I know explictly call SystemNavigator.pop() and the redux store maintains normal behavior.

Can anyone shed some light on this?

brianegan commented 3 years ago

Hm, that sounds odd -- I really have no idea how the same initialization code would run, but you'd get a different result!

Personally, I've always had mixed results reconnecting to Flutter apps in Android after I accidentally close it out. I almost always restart the app myself, haha.

Unfortunately -- while it's gotten better over time, I think it's still common for the reconnection to fail -- but I see that on non-Redux projects as well. Overall, I'd consider filing a bug with the Flutter team directly if this is still plaguing you!