A Flutter plugin that adds type safety when working with SharedPreferences.
The pure Android version can be found here.
Adds type safety to avoid runtime crashes when working with the amazing shared_preferences package.
Create your Preference
objects:
const intPreference = Preference<int>("integer", 3);
Set it's value:
intPreference.set(7);
//If you already have an instance of SharedPreferences, you should pass it:
intPreference.set(7, prefs: await SharedPreferences.getInstance());
And read it:
int currentPreferenceValue = await intPreference.get();
If you already have an instance of SharedPreference
, you can synchronously read values:
SharedPreferences prefs = await SharedPreferences.getInstance();
int currentPreferenceValue = intPreference.getSync(prefs);
This is the Flutter version of my Android Preftils package. You can read more about the reason behind this package here.