Persisted Signals
When you need to store the state of your signals between app launches you can create a PersistedSignal
from this example code.
You need to have a store that can be SharedPreferences, SQLite, in memory, or any other storage solution. The store just needs to be able to save and restore the data.
You can create an in-memory store for testing:
For this example we are going to be using SharedPreferences:
By default we can encode and decode the value to and from JSON:
This can work in a lot of cases, but we might want to handle specific cases like enums:
Or if you are in Flutter we can persist color values:
Example
Now when we run the app and make changes, if we close the app and reopen it, the changes will persist offline.