How can I load all saved in SharedPreferences?
I have saved lots of bools and need to load all to a list!
This is how I save:
SharedPreferences sharedPreferences;
bool isfavorit;
@override
void initState() {
super.initState();
SharedPreferences.getInstance().then((SharedPreferences sp) {
sharedPreferences = sp;
isfavorit = sharedPreferences.getBool('${widget.id}');
// will be null if never previously saved
if (isfavorit == null) {
isfavorit = false;
persist(isfavorit); // set an initial value
}
setState(() {});
});
}
void persist(bool value) {
setState(() {
isfavorit = value;
});
sharedPreferences?.setBool('${widget.id}', value);
}