hydrate method

void hydrate()

Populates the internal state storage with the latest state. This should be called when using the HydratedMixin directly within the constructor body.

class CounterBloc extends Bloc<CounterEvent, int> with HydratedMixin {
 CounterBloc() : super(0) {
   hydrate();
 }
 ...
}

Implementation

void hydrate() {
  try {
    final stateJson = _toJson(state);
    if (stateJson != null) {
      _storage.write(storageToken, stateJson).then((_) {}, onError: onError);
    }
  } catch (error, stackTrace) {
    onError(error, stackTrace);
    if (error is StorageNotFound) rethrow;
  }
}