Transforms a Stream.
When a stream's Stream.transform method is invoked with a StreamTransformer, the stream calls the bind method on the provided transformer. The resulting stream is then returned from the Stream.transform method.
Conceptually, a transformer is simply a function from Stream to Stream that is encapsulated into a class.
It is good practice to write transformers that can be used multiple times.
All other transforming methods on Stream, such as Stream.map, Stream.where or Stream.expand can be implemented using Stream.transform. A StreamTransformer is thus very powerful but often also a bit more complicated to use.
The StreamTransformer.fromHandlers constructor allows passing separate
callbacks to react to events, errors, and the end of the stream.
The StreamTransformer.fromBind constructor creates a StreamTransformer
whose bind method is implemented by calling the function passed to the
constructor.
- Implementers
Constructors
-
StreamTransformer(StreamSubscription<
T> onListen(Stream<S> stream, bool cancelOnError)) -
Creates a StreamTransformer based on the given
onListen
callback.constfactory -
StreamTransformer.fromBind(Stream<
T> bind(Stream<S> )) -
Creates a StreamTransformer based on a
bind
callback.factory -
StreamTransformer.fromHandlers({void handleData(S data, EventSink<
T> sink)?, void handleError(Object error, StackTrace stackTrace, EventSink<T> sink)?, void handleDone(EventSink<T> sink)?}) -
Creates a StreamTransformer that delegates events to the given functions.
factory
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
bind(
Stream< S> stream) → Stream<T> -
Transforms the provided
stream
. -
cast<
RS, RT> () → StreamTransformer< RS, RT> -
Provides a
StreamTransformer<RS, RT>
view of this stream transformer. -
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
Static Methods
-
castFrom<
SS, ST, TS, TT> (StreamTransformer< SS, ST> source) → StreamTransformer<TS, TT> -
Adapts
source
to be aStreamTransformer<TS, TT>
.