Bloc<Event, State> class

Takes a Stream of Events as input and transforms them into a Stream of States as output.

Inheritance
Implemented types
Available Extensions

Constructors

Bloc()
Takes a Stream of Events as input and transforms them into a Stream of States as output.

Properties

first Future<State>
The first element of this stream. [...]
read-only, inherited
hashCode int
The hash code for this object. [...]
read-only, inherited
initialState → State
Returns the state before any events have been added.
read-only
isBroadcast bool
Returns whether the Stream<State> is a broadcast stream.
read-only, override
isEmpty Future<bool>
Whether this stream contains any elements. [...]
read-only, inherited
last Future<State>
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<State>
The single element of this stream. [...]
read-only, inherited
state → State
Returns the current state of the bloc.
read-only

Methods

add(Event 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.
override
any(bool test(State element)) Future<bool>
Checks whether test accepts any element provided by this stream. [...]
inherited
asBroadcastStream({void onListen(StreamSubscription<State> subscription), void onCancel(StreamSubscription<State> subscription)}) Stream<State>
Returns a multi-subscription stream that produces the same events as this. [...]
inherited
asyncExpand<E>(Stream<E> convert(State event)) Stream<E>
Transforms each element into a sequence of asynchronous events. [...]
inherited
asyncMap<E>(FutureOr<E> convert(State 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, override
contains(Object needle) Future<bool>
Returns whether needle occurs in the elements provided by this stream. [...]
inherited
distinct([bool equals(State previous, State next)]) Stream<State>
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<State>
Returns the value of the indexth data event of this stream. [...]
inherited
every(bool test(State element)) Future<bool>
Checks whether test accepts all elements provided by this stream. [...]
inherited
expand<S>(Iterable<S> convert(State element)) Stream<S>
Transforms each element of this stream into a sequence of elements. [...]
inherited
firstWhere(bool test(State element), {State orElse()}) Future<State>
Finds the first element of this stream matching test. [...]
inherited
fold<S>(S initialValue, S combine(S previous, State element)) Future<S>
Combines a sequence of values by repeatedly applying combine. [...]
inherited
forEach(void action(State element)) Future
Executes action on each element of this stream. [...]
inherited
handleError(Function onError, {bool test(dynamic error)}) Stream<State>
Creates a wrapper Stream that intercepts some errors from this stream. [...]
inherited
join([String separator = ""]) Future<String>
Combines the string representation of elements into a single string. [...]
inherited
lastWhere(bool test(State element), {State orElse()}) Future<State>
Finds the last element in this stream matching test. [...]
inherited
listen(void onData(State), {Function onError, void onDone(), bool cancelOnError}) StreamSubscription<State>
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.
override
map<S>(S convert(State event)) Stream<S>
Transforms each element of this stream into a new stream event. [...]
inherited
mapEventToState(Event event) Stream<State>
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>.
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.
onEvent(Event event) → void
Called whenever an event is added to the bloc. A great spot to add logging/analytics at the individual bloc level.
onTransition(Transition<Event, State> 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.
pipe(StreamConsumer<State> streamConsumer) Future
Pipes the events of this stream into streamConsumer. [...]
inherited
reduce(State combine(State previous, State element)) Future<State>
Combines a sequence of values by repeatedly applying combine. [...]
inherited
singleWhere(bool test(State element), {State orElse()}) Future<State>
Finds the single element in this stream matching test. [...]
inherited
skip(int count) Stream<State>
Skips the first count data events from this stream. [...]
inherited
skipWhile(bool test(State element)) Stream<State>
Skip data events from this stream while they are matched by test. [...]
inherited
take(int count) Stream<State>
Provides at most the first count data events of this stream. [...]
inherited
takeWhile(bool test(State element)) Stream<State>
Forwards data events while test is successful. [...]
inherited
timeout(Duration timeLimit, {void onTimeout(EventSink<State> sink)}) Stream<State>
Creates a new stream with the same events as this stream. [...]
inherited
toList() Future<List<State>>
Collects all elements of this stream in a List. [...]
inherited
toSet() Future<Set<State>>
Collects the data of this stream in a Set. [...]
inherited
toString() String
A string representation of this object. [...]
inherited
transform<S>(StreamTransformer<State, S> streamTransformer) Stream<S>
Applies streamTransformer to this stream. [...]
inherited
transformEvents(Stream<Event> events, Stream<State> next(Event)) Stream<State>
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. [...]
transformStates(Stream<State> states) Stream<State>
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. [...]
where(bool test(State event)) Stream<State>
Creates a new stream from this stream that discards some elements. [...]
inherited

Operators

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