According to documentation, RestorableBool class is a RestorableProperty that knows how to store and restore a bool. One example of RestorableBool is given by flutter itself in the flutter gallery project.
The same result can be achieved by using simple boolean. Click here to get the code of same screen using simple bool.
Is there any special benefits for RestorableBool over usual bool or is there any special context at which we have to use RestorableBool?
Anyone to help?Thanks in advance.
2
Answers
The example in your code doesn’t do the same thing, well it does in your code, but it wouldn’t in all cases.
The difference is that
RestorableBool
is reset to it’s initial state, even if it is already in that state, meanwhile your code flips the bool to the opposite value.Mobile operating systems fool you into thinking all the apps you have open are actually running. But they are not. The topmost is running, all others are killed. Their last screenshot is kept to uphold the illusion of being able to hold multiple apps open.
When you "switch apps", what happens is that the app that wasn’t in the foreground is opened and it’s state is restored from memory.
If you don’t do anything, your app cannot handle this and will just start as if it was started from scratch.
In Flutter, the Restoration Manager can help you store your state and restore your state. Other options are available, I think hydrated_bloc is probably useful if you are working with
bloc
patterns.