BaseBloc class

A base bloc that extends the Bloc class for providing additional functionality. When the bloc is created, InitializeEvent is dispatched if the initial state is StateUninitialized. If the state is not StateUninitialized, then InitializeEvent won't be dispatched and the initialize method won't be called. In order to do some initializations, you can override the initialize method If you need to yield some state upon initialization, then you can use the onInitialized method

Inheritance
Available Extensions

Constructors

BaseBloc()

Properties

first Future<BlocState>
The first element of this stream. [...]
read-only, inherited
hashCode int
The hash code for this object. [...]
read-only, inherited
initialState BlocState
The default initial state of the bloc is StateUninitialized If you override initialState to some other state rather than StateUninitialized, then InitializeEvent won't be dispatched, and the initialize method won't be called
read-only, override
isBroadcast bool
Returns whether the Stream<State> is a broadcast stream.
read-only, inherited
isEmpty Future<bool>
Whether this stream contains any elements. [...]
read-only, inherited
last Future<BlocState>
The last element of this stream. [...]
read-only, inherited
length Future<int>
The number of elements in this stream. [...]
read-only, inherited
runtimeType Type
A representation of the runtime type of the object.
read-only, inherited
single Future<BlocState>
The single element of this stream. [...]
read-only, inherited
state BlocState
Returns the current state of the bloc.
read-only, inherited

Methods

add(BlocEvent event) → void
Notifies the bloc of a new event which triggers mapEventToState. If close has already been called, any subsequent calls to add will be delegated to the onError method which can be overriden at the bloc as well as the BlocDelegate level.
inherited
any(bool test(BlocState element)) Future<bool>
Checks whether test accepts any element provided by this stream. [...]
inherited
asBroadcastStream({void onListen(StreamSubscription<BlocState> subscription), void onCancel(StreamSubscription<BlocState> subscription)}) Stream<BlocState>
Returns a multi-subscription stream that produces the same events as this. [...]
inherited
asyncExpand<E>(Stream<E> convert(BlocState event)) Stream<E>
Transforms each element into a sequence of asynchronous events. [...]
inherited
asyncMap<E>(FutureOr<E> convert(BlocState event)) Stream<E>
Creates a new stream with each data event of this stream asynchronously mapped to a new event. [...]
inherited
cast<R>() Stream<R>
Adapt this stream to be a Stream<R>. [...]
inherited
close() Future<void>
Closes the event and state Streams. This method should be called when a bloc is no longer needed. Once close is called, events that are added will not be processed and will result in an error being passed to onError. In addition, if close is called while events are still being processed, the bloc will continue to process the pending events to completion.
@mustCallSuper, inherited
contains(Object needle) Future<bool>
Returns whether needle occurs in the elements provided by this stream. [...]
inherited
distinct([bool equals(BlocState previous, BlocState next)]) Stream<BlocState>
Skips data events if they are equal to the previous data event. [...]
inherited
drain<E>([E futureValue]) Future<E>
Discards all data on this stream, but signals when it is done or an error occurred. [...]
inherited
elementAt(int index) Future<BlocState>
Returns the value of the indexth data event of this stream. [...]
inherited
eventToState(BlocEvent event) Stream<BlocState>
Must be implemented when a class extends BaseBloc. Takes the incoming event as the argument. eventToState is called whenever an event is added. eventToState must convert that event into a new state and return the new state in the form of a Stream<State>.
every(bool test(BlocState element)) Future<bool>
Checks whether test accepts all elements provided by this stream. [...]
inherited
expand<S>(Iterable<S> convert(BlocState element)) Stream<S>
Transforms each element of this stream into a sequence of elements. [...]
inherited
firstWhere(bool test(BlocState element), {BlocState orElse()}) Future<BlocState>
Finds the first element of this stream matching test. [...]
inherited
fold<S>(S initialValue, S combine(S previous, BlocState element)) Future<S>
Combines a sequence of values by repeatedly applying combine. [...]
inherited
forEach(void action(BlocState element)) Future
Executes action on each element of this stream. [...]
inherited
handleError(Function onError, {bool test(dynamic error)}) Stream<BlocState>
Creates a wrapper Stream that intercepts some errors from this stream. [...]
inherited
initialize() Stream<StateInitializing>
Used for initializing the block. Can update progress by yielding StateInitializing. If you want to yield an error, then throw an exception. If an exception is thrown, then a StateError is yielded
join([String separator = ""]) Future<String>
Combines the string representation of elements into a single string. [...]
inherited
lastWhere(bool test(BlocState element), {BlocState orElse()}) Future<BlocState>
Finds the last element in this stream matching test. [...]
inherited
listen(void onData(BlocState), {Function onError, void onDone(), bool cancelOnError}) StreamSubscription<BlocState>
Adds a subscription to the Stream<State>. Returns a StreamSubscription which handles events from the Stream<State> using the provided onData, onError and onDone handlers.
inherited
map<S>(S convert(BlocState event)) Stream<S>
Transforms each element of this stream into a new stream event. [...]
inherited
mapEventToState(BlocEvent event) Stream<BlocState>
Must be implemented when a class extends bloc. Takes the incoming event as the argument. mapEventToState is called whenever an event is added. mapEventToState must convert that event into a new state and return the new state in the form of a Stream<State>.
override
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed. [...]
inherited
onError(Object error, StackTrace stacktrace) → void
Called whenever an error is thrown within mapEventToState. By default all errors will be ignored and bloc functionality will be unaffected. The stacktrace argument may be null if the state stream received an error without a stacktrace. A great spot to handle errors at the individual Bloc level.
inherited
onEvent(BlocEvent event) → void
Called whenever an event is added to the bloc. A great spot to add logging/analytics at the individual bloc level.
inherited
onInitialized() Stream<BlocState>
Called when the bloc is initialized (when StateInitialized is yielded Can be used for adding some event or for yielding some state after initialization is done
onTransition(Transition<BlocEvent, BlocState> transition) → void
Called whenever a transition occurs with the given transition. A transition occurs when a new event is added and mapEventToState executed. onTransition is called before a bloc's state has been updated. A great spot to add logging/analytics at the individual bloc level.
inherited
pipe(StreamConsumer<BlocState> streamConsumer) Future
Pipes the events of this stream into streamConsumer. [...]
inherited
reduce(BlocState combine(BlocState previous, BlocState element)) Future<BlocState>
Combines a sequence of values by repeatedly applying combine. [...]
inherited
singleWhere(bool test(BlocState element), {BlocState orElse()}) Future<BlocState>
Finds the single element in this stream matching test. [...]
inherited
skip(int count) Stream<BlocState>
Skips the first count data events from this stream. [...]
inherited
skipWhile(bool test(BlocState element)) Stream<BlocState>
Skip data events from this stream while they are matched by test. [...]
inherited
take(int count) Stream<BlocState>
Provides at most the first count data events of this stream. [...]
inherited
takeWhile(bool test(BlocState element)) Stream<BlocState>
Forwards data events while test is successful. [...]
inherited
timeout(Duration timeLimit, {void onTimeout(EventSink<BlocState> sink)}) Stream<BlocState>
Creates a new stream with the same events as this stream. [...]
inherited
toList() Future<List<BlocState>>
Collects all elements of this stream in a List. [...]
inherited
toSet() Future<Set<BlocState>>
Collects the data of this stream in a Set. [...]
inherited
toString() String
Returns a string representation of this object.
inherited
transform<S>(StreamTransformer<BlocState, S> streamTransformer) Stream<S>
Applies streamTransformer to this stream. [...]
inherited
transformEvents(Stream<BlocEvent> events, Stream<BlocState> next(BlocEvent)) Stream<BlocState>
Transforms the events stream along with a next function into a Stream<State>. Events that should be processed by mapEventToState need to be passed to next. By default asyncExpand is used to ensure all events are processed in the order in which they are received. You can override transformEvents for advanced usage in order to manipulate the frequency and specificity with which mapEventToState is called as well as which events are processed. [...]
inherited
transformStates(Stream<BlocState> states) Stream<BlocState>
Transforms the Stream<State> into a new Stream<State>. By default transformStates returns the incoming Stream<State>. You can override transformStates for advanced usage in order to manipulate the frequency and specificity at which transitions (state changes) occur. [...]
inherited
where(bool test(BlocState event)) Stream<BlocState>
Creates a new stream from this stream that discards some elements. [...]
inherited

Operators

operator ==(dynamic other) bool
The equality operator. [...]
inherited