state property
The current "state" of this StateNotifier
.
Updating this variable will synchronously call all the listeners. Notifying the listeners is O(N) with N the number of listeners.
Updating the state will throw if at least one listener throws.
Implementation
@override
State get state {
final storage = HydratedStateNotifier.storage;
if (_state != null) return _state!;
try {
final stateJson = storage.read(storageToken) as Map<dynamic, dynamic>?;
if (stateJson != null) {
_state = _fromJson(stateJson);
}
return _state ??= super.state;
} catch (error, stackTrace) {
onError?.call(error, stackTrace);
return _state = super.state;
}
}
Implementation
@override
set state(State value) {
final storage = HydratedStateNotifier.storage;
try {
final stateJson = _toJson(value);
if (stateJson != null) {
storage.write(storageToken, stateJson).then((_) {}, onError: onError);
}
} catch (error, stackTrace) {
onError?.call(error, stackTrace);
}
_state = value;
super.state = value;
}