Bloc<S> class abstract

The central class behind this library

It is responsible for processing all the events and broadcasting corresponding changes made to the state. R is the type which subclasses Bloc S is the type of value which this bloc broadcasts. S must implement equality


Bloc({S? initialState, BlocMonitor<Bloc, dynamic> monitor = const BlocEventsPrinter()})
initialState is the state which is set at initialization. if its null, the initial state is set to busy.


error → dynamic
no setter
hasError bool
no setter
hashCode int
The hash code for this object.
no setterinherited
hasState bool
no setter
isBusy bool
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
state → S
no setter
stream Stream<S?>
Broadcast Stream to which all builders listen
no setter


addListener(BlocListener callback) → void
Adds a callback function to the list on active callbacks
close() Future<void>
Send a done event and disposes the stream
nextState(S? currentState, S update) → S?
Called to calculate the new state
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
notifyListeners(BlocEventType type) → void
Calls all callbacks currently active
onActivate() → void
Called when Bloc get the first listener and stream is created
onDeactivate() → void
Called when Bloc has no more listeners and stream is being closed
refresh() → void
Broadcasts the same state
removeListener(BlocListener callback) → void
Removes a callback function from the list
setBusy({String? event}) → void
Called by blocs (subclasses) when the updated state isn't available immediately
setError(dynamic error, {String? event}) → void
Called by blocs (subclasses) when an error occurs
setState(S update, {String? event}) → void
Called by blocs (subclasses) when the state is updated
toString() String
A string representation of this object.


operator ==(Object other) bool
The equality operator.