onEach<T> abstract method

Future<void> onEach<T>(
  1. Stream<T> stream, {
  2. required void onData(
    1. T data
    ),
  3. void onError(
    1. Object error,
    2. StackTrace stackTrace
    )?,
})

Subscribes to the provided stream and invokes the onData callback when the stream emits new data.

onEach completes when the event handler is cancelled or when the provided stream has ended.

If onError is omitted, any errors on this stream are considered unhandled, and will be thrown by onEach. As a result, the internal subscription to the stream will be canceled.

If onError is provided, any errors on this stream will be passed on to onError and will not result in unhandled exceptions or cancelations to the internal stream subscription.

Note: The stack trace argument may be StackTrace.empty if the stream received an error without a stack trace.

Implementation

Future<void> onEach<T>(
  Stream<T> stream, {
  required void Function(T data) onData,
  void Function(Object error, StackTrace stackTrace)? onError,
});