addStream<T> method
StreamSubscription<T>
addStream<T>(
- Stream<
T> stream, { - S onData(
- S state,
- T event
- S onError(
- S state,
- Object error,
- StackTrace stackTrace
- S onDone(
- S state
- bool? cancelOnError,
Adds a stream
that asynchronously contributes to the state through
onData
, onError
and onDone
reducers. These functions receive the
current state and the events of the Stream to produce a new state.
Implementation
StreamSubscription<T> addStream<T>(
Stream<T> stream, {
S Function(S state, T event)? onData,
S Function(S state, Object error, StackTrace stackTrace)? onError,
S Function(S state)? onDone,
bool? cancelOnError,
}) =>
stream.listen(
onData == null
? null
: (event) => update((state) => onData(state, event)),
onError: onError == null
? null
: (Object error, StackTrace stackTrace) =>
update((state) => onError(state, error, stackTrace)),
onDone: onDone == null ? null : () => update(onDone),
cancelOnError: cancelOnError);