StreamingSharedPreferences class

StreamingSharedPreferences is like SharedPreferences, but reactive.

It wraps SharedPreferences with a Stream-based layer, allowing you to listen to changes in the underlying values.

Every preferences.get(..) method returns a Preference which is a Stream. A Preference emits values whenever the underlying value updates. You can also obtain the current value synchronously by calling preferences.get(..).getValue().

To set values, every Preference has a convenient setValue() method. You can also call preferences.set(..) like you would do with normal SharedPreferences.

While you can connect a Preference to your UI with a StreamBuilder widget, it is recommended to use a PreferenceBuilder, as that gets rid of the initial flicker and you don't need to provide initialData parameter for it.

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

clear() Future<bool>
Clears the entire key-value storage by removing all keys and values.
getBool(String key, {required bool defaultValue}) Preference<bool>
Starts with the current bool value for the given key, then emits a new value every time there are changes to the value associated with key.
getCustomValue<T>(String key, {required T defaultValue, required PreferenceAdapter<T> adapter}) Preference<T>
Creates a Preference with a custom type. Requires an implementation of a PreferenceAdapter.
getDouble(String key, {required double defaultValue}) Preference<double>
Starts with the current double value for the given key, then emits a new value every time there are changes to the value associated with key.
getInt(String key, {required int defaultValue}) Preference<int>
Starts with the current int value for the given key, then emits a new value every time there are changes to the value associated with key.
getKeys() Preference<Set<String>>
Emits all the keys that currently exist - which means keys that have a non-null value.
getString(String key, {required String defaultValue}) Preference<String>
Starts with the current String value for the given key, then emits a new value every time there are changes to the value associated with key.
getStringList(String key, {required List<String> defaultValue}) Preference<List<String>>
Starts with the current String list value for the given key, then emits a new value every time there are changes to the value associated with key.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
remove(String key) Future<bool>
Removes the value associated with key and notifies all active listeners that key was removed. When a key is removed, the listeners associated with it will emit their defaultValue value.
setBool(String key, bool value) Future<bool>
Sets a bool value and notifies all active listeners that there's a new value for the key.
setCustomValue<T>(String key, T value, {required PreferenceAdapter<T> adapter}) Future<bool>
Sets a value of custom type T and notifies all active listeners that there's a new value for the key.
setDouble(String key, double value) Future<bool>
Sets a double value and notifies all active listeners that there's a new value for the key.
setInt(String key, int value) Future<bool>
Sets a int value and notifies all active listeners that there's a new value for the key.
setString(String key, String value) Future<bool>
Sets a String value and notifies all active listeners that there's a new value for the key.
setStringList(String key, List<String> values) Future<bool>
Sets a String list value and notifies all active listeners that there's a new value for the key.
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Properties

instance Future<StreamingSharedPreferences>
Obtain an instance to StreamingSharedPreferences.
no setter