Bloc class abstract
Business Logic Component (BLoC).
The class that implements the core business logic, and that should be placed between UI and data source. BLoC accepts UI actions from the widget and in return notifies the widget's about changes in UI state or initiate navigation actions.
This class implements methods that improve and simplify process of delivering business-logic states changes and navigation actions to widgets.
Current solution contains methods to register states that you want to provide to widgets (registerState), send this states (addState, addStateSource, addStatesSource) and navigation actions (addNavigation, addNavigationSource).
class CounterBloc extends Bloc {
int value = 0;
CounterBloc() {
registerState<int>(initialState: value);
}
void increment() => addState(++value);
}
Widgets should use getStateStream and navigationStream to subscribe on Bloc events.
Constructors
- Bloc({ })
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- isDisposed → bool
-
Defines whether that Bloc was closed.
no setter
-
Returns navigation stream.
Returns
null
if this Bloc was disposed.no setter - runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
- Adds navigation data to navigationStream.
-
Adds Stream of
RouteData
as navigation events source. -
addState<
S> (S uiState) → void -
Adds state of
S
type to the stream that corresponding to state type. -
addStateSource<
S> (Future< S> source, {void onData(S data)?, void onDone()?, void onError(dynamic error)?}) → StreamSubscription<S> ? -
Adds Future that should be returned by state of
S
type as source of state. -
addStatesSource<
S> (Stream< S> source, {void onData(S data)?, void onDone()?, void onError(dynamic error)?}) → StreamSubscription<S> ? -
Adds states Stream of
S
type as source of states. -
containsState<
S> () → bool -
Checks whether a state of
S
type was registered before. Returnsfalse
if this Bloc was disposed. -
dispose(
) → void - Releases resources and closes streams.
-
getState<
S> () → S? -
Returns last state of
S
type or null if isDisposed -
getStateStream<
S> () → Stream< S> ? -
Returns states stream according to type
S
. Returnsnull
if this Bloc was disposed. -
initialState<
S> () → S -
Returns initial value for state of
S
type. Returnsnull
if this Bloc was disposed. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
registerState<
S> ({S? initialState}) → void -
Registers state of
S
type that can be processed by this Bloc. -
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited