PreferenceNotifier<T> class
abstract
A state notifier whose state is backed by a shared preference.
The value of the shared preference is available as state. However, the value can be changed by using setValue. The class will save the updated value to the platform's persistent shared preferences, then notify any listeners of the updated value.
- Inheritance
-
- Object
- StateNotifier<
T> - PreferenceNotifier
- Implementers
Constructors
- PreferenceNotifier(T state)
Properties
- debugState → T
-
A development-only way to access state outside of StateNotifier.
no setterinherited
- defaultValue → T
-
The fallback value to emit when there's no stored value associated
with the key.
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
- hasListeners → bool
-
If a listener has been added using addListener and hasn't been removed yet.
no setterinherited
- key → String
-
The preference key.
no setter
- mounted → bool
-
Whether dispose was called or not.
no setterinherited
- onError ↔ ErrorListener?
-
A callback for error reporting if one of the listeners added with addListener throws.
getter/setter pairinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- state ↔ T
-
The current "state" of this StateNotifier.
getter/setter pairinherited
-
stream
→ Stream<
T> -
A broadcast stream representation of a StateNotifier.
no setterinherited
Methods
-
addListener(
Listener< T> listener, {bool fireImmediately = true}) → RemoveListener -
Subscribes to this object.
inherited
-
clear(
) → Future< bool> - Clear, or in other words, remove, the value. Effectively sets the value to a null value. After removing a value, the notifier will emit defaultValue once.
-
dispose(
) → void -
Frees all the resources associated with this object.
inherited
-
getValue(
) → T - Get the latest value from the persistent storage synchronously.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
setValue(
T value) → Future< bool> - Sets the value of the underlying shared preference.
-
toString(
) → String -
A string representation of this object.
inherited
-
updateShouldNotify(
T old, T current) → bool -
Whether to notify listeners or not when state changes
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
watchBool(
Ref< Object?> ref, String key, {required bool defaultValue}) → PreferenceNotifier<bool> -
Preference notifier that starts with the current bool value for the
given
key, then emits a new value every time there are chanegs to the value associated with the givenkey. -
watchCustomValue<
T> (Ref< Object?> ref, String key, {required T defaultValue, required PreferenceAdapter<T> adapter}) → PreferenceNotifier<T> -
Preference notifier that starts with the current custom value for the
given
key, then emits a new value every time there are chanegs to the value associated with the givenkey. -
watchDouble(
Ref< Object?> ref, String key, {required double defaultValue}) → PreferenceNotifier<double> -
Preference notifier that starts with the current double value for the
given
key, then emits a new value every time there are chanegs to the value associated with the givenkey. -
watchEnum<
T extends Enum> (Ref< Object?> ref, String key, {required T defaultValue, required List<T> values}) → PreferenceNotifier<T> -
Preference notifier that starts with the current enum value for the
given
key, then emits a new value every time there are chanegs to the value associated with the givenkey. -
watchInt(
Ref< Object?> ref, String key, {required int defaultValue}) → PreferenceNotifier<int> -
Preference notifier that starts with the current int value for the
given
key, then emits a new value every time there are chanegs to the value associated with the givenkey. -
watchString(
Ref< Object?> ref, String key, {required String defaultValue}) → PreferenceNotifier<String> -
Preference notifier that starts with the current string value for the
given
key, then emits a new value every time there are chanegs to the value associated with the givenkey. -
watchStringList(
Ref< Object?> ref, String key, {required List<String> defaultValue}) → PreferenceNotifier<List< String> > -
Preference notifier that starts with the current string list value for the
given
key, then emits a new value every time there are chanegs to the value associated with the givenkey.