listenAndPump method Null safety

StreamSubscription<T> listenAndPump(
  1. void onData(
    1. T event
    ),
  2. {Function? onError,
  3. void onDone(
      )?,
    1. bool? cancelOnError}
    )

    Returns a StreamSubscription similar to listen, but with the added benefit that it primes the stream with the current value, rather than waiting for the next value. This should not be called in onInit or anywhere else during the build process.

    Implementation

    StreamSubscription<T> listenAndPump(void Function(T event) onData,
        {Function? onError, void Function()? onDone, bool? cancelOnError}) {
      final subscription = listen(
        onData,
        onError: onError,
        onDone: onDone,
        cancelOnError: cancelOnError,
      );
    
      subject.add(value);
    
      return subscription;
    }