StreamListener<T> class

A Widget which manages a Subscription to a Stream and exposes callbacks: onData, onError, and onDone.

StreamListener<int>(
  stream: Stream.fromIterable([0, 1, 2, 3]), // Stream being subscribed to
  onData: (data) {
    // React to the emitted data
  },
  onError: (error) {
    // Optionally handle errors in the Stream
  },
  onDone: () {
    // Optionally react to when the Stream is closed
  },
  cancelOnError: true, // Defaults to false
  child: Container(),
)
Inheritance

Constructors

StreamListener({Key? key, required Stream<T> stream, required StreamOnDataListener<T> onData, required Widget child, StreamOnErrorListener? onError, StreamOnDoneListener? onDone, bool cancelOnError = false})
A Widget which manages a Subscription to a Stream and exposes callbacks: onData, onError, and onDone.
const

Properties

cancelOnError bool
If cancelOnError is true, the subscription is automatically canceled when the first error event is delivered. The default is false.
final
child Widget
The widget which will be rendered as a direct descendant of the StreamListener.
final
hashCode int
The hash code for this object.
no setterinherited
key Key?
Controls how one widget replaces another widget in the tree.
finalinherited
onData StreamOnDataListener<T>
On each data event from the stream, the subscriber's onData handler is called.
final
onDone StreamOnDoneListener?
If this stream closes and sends a done event, the onDone handler is called. If onDone is null, nothing happens.
final
onError StreamOnErrorListener?
On errors from this stream, the onError handler is called with the error object and possibly a stack trace.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
stream Stream<T>
The Stream which will be subscribed to.
final

Methods

createElement() StatefulElement
Creates a StatefulElement to manage this widget's location in the tree.
inherited
createState() → _StreamListenerState
Creates the mutable state for this widget at a given location in the tree.
override
debugDescribeChildren() List<DiagnosticsNode>
Returns a list of DiagnosticsNode objects describing this node's children.
inherited
debugFillProperties(DiagnosticPropertiesBuilder properties) → void
Add additional properties associated with the node.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toDiagnosticsNode({String? name, DiagnosticsTreeStyle? style}) DiagnosticsNode
Returns a debug representation of the object that is used by debugging tools and by DiagnosticsNode.toStringDeep.
inherited
toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) String
A string representation of this object.
inherited
toStringDeep({String prefixLineOne = '', String? prefixOtherLines, DiagnosticLevel minLevel = DiagnosticLevel.debug}) String
Returns a string representation of this node and its descendants.
inherited
toStringShallow({String joiner = ', ', DiagnosticLevel minLevel = DiagnosticLevel.debug}) String
Returns a one-line detailed description of the object.
inherited
toStringShort() String
A short, textual description of this widget.
inherited

Operators

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