forEach<T> abstract method

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

when the stream emits new data and the result of onData is emitted.

forEach 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 forEach. 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> forEach<T>(
  Stream<T> stream, {
  required State Function(T data) onData,
  State Function(Object error, StackTrace stackTrace)? onError,
});