HydratedMixin<State> mixin

A mixin which enables automatic state persistence for StateController and StateNotifier classes.

The hydrate method must be invoked in the constructor body when using the HydratedMixin directly.

If a mixin is not necessary, it is recommended to extend HydratedStateController and HydratedStateNotifier respectively.

class Counter extends StateNotifier<int> with HydratedMixin {
 Counter() : super(0) {
   hydrate();
 }
 ...
}

See also:

Superclass Constraints
Mixin Applications

Properties

debugState → State
A development-only way to access state outside of StateNotifier.
no setterinherited
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
id String
id is used to uniquely identify multiple instances. In most cases it is not necessary; however, if you wish to intentionally have multiple instances, then you must override id and return a unique identifier for each HydratedStateNotifier instance in order to keep the caches independent of each other.
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-setteroverride-getter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
state ↔ State
The current "state" of this StateNotifier.
getter/setter pairoverride
storagePrefix String
Storage prefix which can be overridden to provide a custom storage namespace. Defaults to runtimeType but should be overridden in cases where stored data should be resilient to obfuscation or persist between debug/release builds.
no setter
storageToken String
storageToken is used as registration token for hydrated storage. Composed of storagePrefix and id.
no setter
stream Stream<State>
A broadcast stream representation of a StateNotifier.
no setterinherited

Methods

addListener(Listener<State> listener, {bool fireImmediately = true}) RemoveListener
Subscribes to this object.
inherited
clear() Future<void>
clear is used to wipe or invalidate the cache of a HydratedStateNotifier. Calling clear will delete the cached state of the state_notifier but will not modify the current state of the state_notifier.
dispose() → void
Frees all the resources associated to this object.
inherited
fromJson(Map<String, dynamic> json) → State?
Responsible for converting the Map<String, dynamic> representation of the StateNotifier state into a concrete instance of the StateNotifier state.
hydrate() → void
Populates the internal state storage with the latest state. This should be called when using the HydratedMixin directly within the constructor body.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toJson(State state) Map<String, dynamic>?
Responsible for converting a concrete instance of the StateNotifier state into the the Map<String, dynamic> representation.
toString() String
A string representation of this object.
inherited
updateShouldNotify(State old, State current) bool
Whether to notify listeners or not when state changes
inherited

Operators

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