state property

  1. @override
State state
override

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 {
  if (_state != null) return _state!;
  try {
    final stateJson = _storage.read(storageToken) as Map<dynamic, dynamic>?;
    if (stateJson == null) {
      _state = super.state;
      return super.state;
    }
    final cachedState = _fromJson(stateJson);
    if (cachedState == null) {
      _state = super.state;
      return super.state;
    }
    _state = cachedState;
    return cachedState;
  } catch (error, stackTrace) {
    onError(error, stackTrace);
    _state = super.state;
    return super.state;
  }
}
  1. @override
void state=(State value)
override

Implementation

@override
set state(State value) {
  super.state = value;
  final state = value;
  try {
    final stateJson = _toJson(state);
    if (stateJson != null) {
      _storage.write(storageToken, stateJson).then((_) {}, onError: onError);
    }
  } catch (error, stackTrace) {
    onError(error, stackTrace);
    rethrow;
  }
  _state = state;
}