addStatesSource<S> method

  1. @protected
StreamSubscription<S>? addStatesSource<S>(
  1. Stream<S> source, {
  2. void onData(
    1. S data
    )?,
  3. void onDone()?,
  4. void onError(
    1. dynamic error
    )?,
})

Adds states Stream of S type as source of states.

Callbacks onData, onDone, onError help to handle source. Throws ArgumentError if state of such type was not registered. Returns StreamSubscription that provide possibility to pause, resume or cancel source. Returns null if this Bloc was disposed.

WARNING!!! This class doesn't respond for cancellation and closing of source stream. Developer should do it on his own, if necessary.

Implementation

@protected
StreamSubscription<S>? addStatesSource<S>(Stream<S> source,
    {void Function(S data)? onData,
    void Function()? onDone,
    void Function(dynamic error)? onError}) {
  return isDisposed
      ? null
      : (_store[S] as _StateDeliveryController<S>).addSource(source,
          onData: onData, onDone: onDone, onError: onError);
}