hydrate method

Future<void> hydrate()

Hydrates the bloc.

  • If the bloc is already hydrated, this method does nothing.
  • If the bloc is not hydrated, this method will try to retrieve the state from the store and set it as the current state.
  • If the bloc is not hydrated and the state cannot be retrieved from the store, the current state will be used.

Implementation

Future<void> hydrate() async {
  if (!isBlocHydrated) {
    var candidateState = await store.retrieve(persitenceKey);
    candidateState ??= currentState;

    setState(candidateState.copyWith(hydrated: true) as S);
    isBlocHydrated = true;
  }
}