DoStreamTransformer<S> class
Invokes the given callback at the corresponding point the the stream lifecycle. For example, if you pass in an onDone callback, it will be invoked when the stream finishes emitting items.
This transformer can be used for debugging, logging, etc. by intercepting the stream at different points to run arbitrary actions.
It is possible to hook onto the following parts of the stream lifecycle:
- onCancel
- onData
- onDone
- onError
- onListen
- onPause
- onResume
In addition, the onEach
argument is called at onData
, onDone
, and
onError
with a StreamNotification passed in. The StreamNotification argument
contains the NotificationKind of event (OnData, OnDone, OnError), and the item or
error that was emitted. In the case of onDone, no data is emitted as part
of the StreamNotification.
If no callbacks are passed in, a runtime error will be thrown in dev mode in order to 'fail fast' and alert the developer that the transformer should be used or safely removed.
Example
Stream.fromIterable([1])
.transform(DoStreamTransformer(
onData: print,
onError: (e, s) => print('Oh no!'),
onDone: () => print('Done')))
.listen(null); // Prints: 1, 'Done'
- Inheritance
-
- Object
- StreamTransformerBase<
S, S> - DoStreamTransformer
Constructors
-
DoStreamTransformer({FutureOr<
void> onCancel()?, void onData(S event)?, void onDone()?, void onEach(StreamNotification<S> notification)?, void onError(Object, StackTrace)?, void onListen()?, void onPause()?, void onResume()?}) - Constructs a StreamTransformer which will trigger any of the provided handlers as they occur.
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
-
onCancel
→ FutureOr<
void> Function()? -
fires when all subscriptions have cancelled.
final
- onData → void Function(S event)?
-
fires when data is emitted
final
- onDone → void Function()?
-
fires on close
final
-
onEach
→ void Function(StreamNotification<
S> notification)? -
fires on data, close and error
final
- onError → void Function(Object, StackTrace)?
-
fires on errors
final
- onListen → void Function()?
-
fires when a subscription first starts
final
- onPause → void Function()?
-
fires when the subscription pauses
final
- onResume → void Function()?
-
fires when the subscription resumes
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
bind(
Stream< S> stream) → Stream<S> -
Transforms the provided
stream
.override -
cast<
RS, RT> () → StreamTransformer< RS, RT> -
Provides a
StreamTransformer<RS, RT>
view of this stream transformer.inherited -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited