Is there a way to save then restore the full state of a Flutter application ?
By full, I mean saving the states of all widgets and objects
For example, a TextField will have the exact text on it, the exact color, highlights,
A GoogleMap will have the exact Zoom states, Markers, Polylines
Every objects internal states will be kept, even private fields.
I can't do it manually for three main reasons:
- There are too many states, any wrong state can lead to a butterfly effect of discrepancy
- Some states of some classes are impossible to get and set as they are internal (private)
- Some states are random at instantiation
I figured out the technical term is https://en.wikipedia.org/wiki/Continuation
There is an important use case for that:
User could Save current state of their work then resume later. (More like "Save" in games)
Solution 1: nvoigt
No, there is no automatism to save "all", because "all" would be impractical and impossible to determine. After all, you don't have endless time or disk space before a mobile operating systems kicks your app out of it's memory, you should not just "dump all" because it might be too much for any real app.
Some good info can be found here:
If you are using the BloC state management approach, it has a package called hydrated_bloc, that basically manages your BloCs storage so it can be restored to it's previous values when you open your app the next time.
Flutter itself seems to have a RestorationManager class to handle this, but it has no automatisms, you need to do that. So all controls or packages you use may not save their state and then you are out of luck and back to the way where you determine what is important and what can be lost.