How to do state restoration in Flutter 2 without StatefulWidget?

197 views Asked by At

I am fairly new to Flutter. I am using Flutter 2 ChangeNotifiers to share state between multiple StatelessWidget-derived screens. That lets me have truly declarative UI and navigation, with no StatefulWidgets used in my app explicitly. Everything works fine.

Now I would like to implement state restoration, but all Flutter state restoration examples rely on StatefulWidgets, effectively requiring potentially shared state to be associated with some specific widget just for the restoration purpose, even though my use case is shared state used by multiple stateless widgets. I mean I haven't had a need for StatefulWidgets so far and it feels like a really bad anti-pattern having to switch to StatefulWidgets just for state restoration and then try to figure out how multiple StatefulWidgets using some single piece of state are supposed to restore it. Am I missing something?

0

There are 0 answers