bloc library

Classes

Bloc<Event extends Object?, State extends Object?>
Takes a Stream of Events as input and transforms them into a Stream of States as output.
BlocBuilder<B extends IStateObservable<S>, S>
BlocBuilder handles building a widget in response to new states. BlocBuilder is analogous to StreamBuilder but has simplified API to reduce the amount of boilerplate code needed as well as bloc-specific performance improvements. Please refer to BlocListener if you want to "do" anything in response to state changes such as navigation, showing a dialog, etc...
BlocBuilderBase<B extends IStateObservable<S>, S>
Base class for widgets that build themselves based on interaction with a specified bloc.
BlocListener<B extends IStateObservable<S>, S>
Takes a BlocWidgetListener and an optional bloc and invokes the listener in response to state changes in the bloc. It should be used for functionality that needs to occur only in response to a state change such as navigation, showing a SnackBar, showing a Dialog, etc... The listener is guaranteed to only be called once for each state change unlike the builder in BlocBuilder.
BlocListenerBase<B extends IStateObservable<S>, S>
Base class for widgets that listen to state changes in a specified bloc.
BlocScope<T extends IStateObservable<Object?>>
Takes a Create function that is responsible for creating the Bloc and a child which will have access to the instance via BlocScope.of(context). It is used as a dependency injection (DI) widget so that a single instance of a Bloc can be provided to multiple widgets within a subtree.
Change<State>
A Change represents the change from one State to another. A Change consists of the currentState and nextState.
GlobalScope
Global scope
IBloc<Event extends Object?, State extends Object?>
An interface to implement the Publisher/Subscriber pattern for Bloc. Takes a Stream of Events as input and transforms them into a Stream of States as output.
IBlocObserver
An interface for observing the behavior of Bloc instances.
IBlocSink<Event extends Object?>
A Bloc Sink interface that accepts events both synchronously and asynchronously.
IBlocSubject<State extends Object?>
Interface to observe states stream. Current state available as property. Bloc Subject to implement the Publisher/Subscriber pattern
IStateObservable<T extends Object?>
An interface to observe states stream. Current state available as property. State subject to implement the Observer (Dependents) pattern
MultiScope
TODO: doc
Scope
Scope, dependency injector/provider/scope
StateStream<State extends Object?>
Broadcast State stream view for BLoC pattern.
Transition<Event, State>
A Transition is the change from one state to another. Consists of the currentState, an event, and the nextState.
ZonedScope
Zoned scope

Extensions

BuildContextScopeX on BuildContext
Exposes BuildContext method to read.

Typedefs

BlocBuilderCondition<S> = bool Function(S previous, S current)
Signature for the buildWhen function which takes the previous state and the current state and is responsible for returning a bool which determines whether to rebuild BlocBuilder with the current state.
BlocListenerCondition<S> = bool Function(S previous, S current)
Signature for the listenWhen function which takes the previous state and the current state and is responsible for returning a bool which determines whether or not to call BlocWidgetListener of BlocListener with the current state.
BlocWidgetBuilder<S> = Widget Function(BuildContext context, S state)
Signature for the builder function which takes the BuildContext and state and is responsible for returning a widget which is to be rendered. This is analogous to the builder function in StreamBuilder.
BlocWidgetListener<S> = void Function(BuildContext context, S state)
Signature for the listener function which takes the BuildContext along with the state and is responsible for executing in response to state changes.
Create<T> = T Function(BuildContext context)
TODO: doc
TransitionFunction<Event, State> = Stream<Transition<Event, State>> Function(Event event)
Signature for a mapper function which takes an Event as input and outputs a Stream of Transition objects.

Exceptions / Errors

BlocUnhandledErrorException
Exception thrown when an unhandled error occurs within a bloc.
ScopeNotFoundException
The error that will be thrown if Scope.of fails to find a Scope