StreamListener<T> constructor

const StreamListener<T>({
  1. Key? key,
  2. required Stream<T> stream,
  3. required StreamOnDataListener<T> onData,
  4. required Widget child,
  5. StreamOnErrorListener? onError,
  6. StreamOnDoneListener? onDone,
  7. bool cancelOnError = false,
})

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(),
)

Implementation

const StreamListener({
  Key? key,
  required this.stream,
  required this.onData,
  required this.child,
  this.onError,
  this.onDone,
  this.cancelOnError = false,
}) : super(key: key);