addStream<T> method

VoidCallback addStream<T>(
  1. Stream<T> stream, {
  2. DataCallback<T>? onData,
  3. DoneCallback? onDone,
  4. ErrorCallback? onError,
  5. bool cancelOnError = false,
})

Implementation

VoidCallback addStream<T>(Stream<T> stream,
        {DataCallback<T>? onData,
        DoneCallback? onDone,
        ErrorCallback? onError,
        bool cancelOnError = false}) =>
    addSubscription((removeSubscription) => stream
        .listen(
          onData,
          onDone: onDone == null
              ? removeSubscription
              : () {
                  removeSubscription();
                  onDone();
                },
          onError: cancelOnError
              ? onError == null
                  ? (Object error, StackTrace stackTrace) {
                      removeSubscription();
                      Error.throwWithStackTrace(error, stackTrace);
                    }
                  : (Object error, StackTrace stackTrace) {
                      removeSubscription();
                      onError(error, stackTrace);
                    }
              : onError,
        )
        .cancel);