StreamController<T> class

A controller with the stream it controls.

This controller allows sending data, error and done events on its stream. This class can be used to create a simple stream that others can listen on, and to push events to that stream.

It's possible to check whether the stream is paused or not, and whether it has subscribers or not, as well as getting a callback when either of these change.

Implemented types
Implementers

Constructors

StreamController({void onListen(), void onPause(), void onResume(), FutureOr<void> onCancel(), bool sync = false})
factory
A controller with a stream that supports only one single subscriber. [...]
StreamController.broadcast({void onListen(), void onCancel(), bool sync = false})
factory
A controller where stream can be listened to more than once. [...]

Properties

doneFuture
read-only, override
A future which is completed when the stream controller is done sending events. [...]
hashCodeint
read-only, inherited
The hash code for this object. [...]
hasListenerbool
read-only
Whether there is a subscriber on the Stream.
isClosedbool
read-only
Whether the stream controller is closed for adding more events. [...]
isPausedbool
read-only
Whether the subscription would need to buffer events. [...]
onCancel ↔ (FutureOr<void> Function?()?)
read / write
The callback which is called when the stream is canceled. [...]
onListen ↔ (void Function?()?)
read / write
The callback which is called when the stream is listened to. [...]
onPause ↔ (void Function?()?)
read / write
The callback which is called when the stream is paused. [...]
onResume ↔ (void Function?()?)
read / write
The callback which is called when the stream is resumed. [...]
runtimeTypeType
read-only, inherited
A representation of the runtime type of the object.
sinkStreamSink<T>
read-only
Returns a view of this object that only exposes the StreamSink interface.
streamStream<T>
read-only
The stream that this controller is controlling.

Methods

add(T event) → void
override
Sends a data event. [...]
addError(Object error, [StackTrace? stackTrace]) → void
override
Sends or enqueues an error event. [...]
addStream(Stream<T> source, {bool? cancelOnError}) → Future
override
Receives events from source and puts them into this controller's stream. [...]
close() → Future
override
Closes the stream. [...]
noSuchMethod(Invocation invocation) → dynamic
inherited
Invoked when a non-existent method or property is accessed. [...]
toString() → String
inherited
A string representation of this object. [...]

Operators

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

© 2012 the Dart project authors
Licensed under the Creative Commons Attribution-ShareAlike License v4.0.
https://api.dart.dev/stable/2.13.0/dart-async/StreamController-class.html