StreamSubscriptionNotifier<T> constructor

StreamSubscriptionNotifier<T>(
  1. StreamSubscription<T> _sub, {
  2. bool ignoreError = false,
  3. bool cancelOnDispose = true,
  4. bool cancelOnError = false,
  5. bool cancelOnDone = false,
})

A StreamSubscriptionNotifier exposes a StreamSubscription to a ChangeNotifier.

Everytime the StreamSubscription.onData callback gets called the value of this is set to the bew data from StreamSubscription.onData.

When the StreamSubscription.onError callback gets called and ignoreError and cancelOnError are false this StreamSubscriptionNotifier removes all it's handlers. Afterwards this StreamSubscriptionNotifier can no longer emit updates because it does not listen to the StreamSubscription anymore.

When the StreamSubscription.onDone callback gets called and cancelOnDone is false this StreamSubscriptionNotifier removes all it's handlers. Afterwards this StreamSubscriptionNotifier can no longer emit updates because it does not listen to the StreamSubscription anymore.

Implementation

StreamSubscriptionNotifier(
  StreamSubscription<T> this._sub, {
  this.ignoreError = false,
  this.cancelOnDispose = true,
  this.cancelOnError = false,
  this.cancelOnDone = false,
})  : _onErrorNotifier = EmptyValueNotifier.empty(),
      _isDoneNotifier = AdvancedValueNotifier(false),
      _isCancelledNotifier = AdvancedValueNotifier(false),
      _hasValue = false,
      assert(
          !ignoreError || (ignoreError && !cancelOnError),
          "cancelOnError cannot be true, "
          "if you want to ignore incoming errors.") {
  _sub!
    ..onError(_onError)
    ..onDone(_onDone)
    ..onData(_onData);
}