hydrated_bloc library

An extension to package:bloc which automatically persists and restores bloc and cubit states. Built to work with package:bloc.

Classes

Bloc<Event, State>
Takes a Stream of Events as input and transforms them into a Stream of States as output.
BlocBase<State>
An interface for the core functionality implemented by both Bloc and Cubit.
BlocObserver
An interface for observing the behavior of Bloc instances.
Change<State>
A Change represents the change from one State to another. A Change consists of the currentState and nextState.
Cubit<State>
A Cubit is similar to Bloc but has no notion of events and relies on methods to emit new states.
Emitter<State>
An Emitter is a class which is capable of emitting new states.
HydratedAesCipher
Default encryption algorithm. Uses AES256 CBC with PKCS7 padding.
HydratedBloc<Event, State>
Specialized Bloc which handles initializing the Bloc state based on the persisted state. This allows state to be persisted across hot restarts as well as complete app restarts.
HydratedCipher
Abstract cipher can be implemented to customize encryption.
HydratedCubit<State>
Specialized Cubit which handles initializing the Cubit state based on the persisted state. This allows state to be persisted across application restarts.
HydratedStorage
Implementation of Storage which uses package:hive to persist and retrieve state changes from the local device.
Storage
Interface which is used to persist and retrieve state changes.
Transition<Event, State>
A Transition is the change from one state to another. Consists of the currentState, an event, and the nextState.

Mixins

HydratedMixin<State>
A mixin which enables automatic state persistence for Bloc and Cubit classes.

Typedefs

EventHandler<Event, State> = FutureOr<void> Function(Event event, Emitter<State> emit)
An event handler is responsible for reacting to an incoming Event and can emit zero or more states via the Emitter.
EventMapper<Event> = Stream<Event> Function(Event event)
Signature for a function which converts an incoming event into an outbound stream of events. Used when defining custom EventTransformers.
EventTransformer<Event> = Stream<Event> Function(Stream<Event> events, EventMapper<Event> mapper)
Used to change how events are processed. By default events are processed concurrently.
TransitionFunction<Event, State> = Stream<Transition<Event, State>> Function(Event)
@Deprecated - Use on<Event> with an EventTransformer instead. Will be removed in v8.0.0

Exceptions / Errors

BlocUnhandledErrorException
Exception thrown when an unhandled error occurs within a bloc.
HydratedCyclicError
Reports that an object could not be serialized due to cyclic references. When the cycle is detected, a HydratedCyclicError is thrown.
HydratedUnsupportedError
Reports that an object could not be serialized. The unsupportedObject field holds object that failed to be serialized.
StorageNotFound
Exception thrown if there was no HydratedStorage specified. This is most likely due to forgetting to setup the HydratedStorage: