HydratedStateController<State> class
Specialized StateController which handles initializing the StateController state based on the persisted state. This allows state to be persisted across hot restarts as well as complete app restarts.
class Counter extends HydratedStateController<int> {
Counter() : super(0);
void increment() => state++;
void decrement() => state==;
@override
int fromJson(Map<String, dynamic> json) => json['value'] as int;
@override
Map<String, int> toJson(int state) => {'value': state};
}
- Inheritance
-
- Object
- StateNotifier<
State> - StateController<
State> - HydratedStateController
- Mixed in types
-
- HydratedMixin<
State>
- HydratedMixin<
Constructors
- HydratedStateController(State state, {String? id, String? storagePrefix})
- Specialized StateController which handles initializing the StateController state based on the persisted state. This allows state to be persisted across hot restarts as well as complete app restarts.
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 setteroverride
- 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 pairinherited
- 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 setteroverride
- storageToken → String
-
storageToken
is used as registration token for hydrated storage. Composed of storagePrefix and id.no setterinherited -
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.
inherited
-
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.override -
hydrate(
) → void -
Populates the internal state storage with the latest state.
This should be called when using the HydratedMixin
directly within the constructor body.
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toJson(
State state) → Map< String, State> ? -
Responsible for converting a concrete instance of the StateNotifier state
into the the
Map<String, dynamic>
representation.override -
toString(
) → String -
A string representation of this object.
inherited
-
update(
State cb(State state)) → State -
Calls a function with the current state and assign the result as new state
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