notified_preferences library

Classes

NotifiedPreferences
Provides easily creating listenable preferences with SharedPreferences.
NotifiedSettings
Provides Preferences for immediate usage, without having to create a new class.
PreferenceAdapter
Provides utility functions for interacting with SharedPreferences. Cannot be instantiated. Please use the static methods which are provided.
PreferenceNotifier<T>
Stores a Preference in SharedPreferences. When created, will read its own value from SharedPreferences. Notifies all its listeners whenever its value is changed. Changes are written into the corresponding SharedPreferences.
SharedPreferences
Wraps NSUserDefaults (on iOS) and SharedPreferences (on Android), providing a persistent store for simple data.

Extensions

NullablePreferences on SharedPreferences
Adds convenience methods for saving values to SharedPreferences that might be null. If the value is null, the corresponding key is removed.

Typedefs

DecodeJsonPreference<T> = T Function(dynamic json)
Used to instantiate a JSON object from a Preference string.
PreferenceReader<T> = T? Function(String key)
Reads value from key.
PreferenceWriter<T> = Future<bool> Function(String key, T value)
Writes value to key.
ReadPreference<T> = T? Function(SharedPreferences prefs, String key)
Reads a Preference from SharedPreferences.
WritePreference<T> = void Function(SharedPreferences prefs, String key, T value)
Writes a Preference to SharedPreferences.

Exceptions / Errors

PreferenceReadError<T>
An error that is thrown when PreferenceAdapter cannot find a matching Reader for the given Preference Type. Supported Preference types include: String, int, double, bool, List<String> and their nullable versions. If you encounter this, please provide your own Reader with the ReadPreference parameter.
PreferenceWriteError<T>
An error that is thrown when PreferenceAdapter cannot find a matching Writer for the given Preference Type. Supported Preference types include: String, int, double, bool, List<String> and their nullable versions. If you encounter this, please provide your own Writer with the WritePreference parameter.