bindStream method

void bindStream(
  1. Stream<T> stream
)

Binds an existing Stream<T> to this Rx<T> to keep the values in sync. You can bind multiple sources to update the value. Subscriptions close when this Rx is closed, or when the observing widget which created the binding releases its dependencies.

Implementation

void bindStream(Stream<T> stream) {
  if (isDisposed) throw StateError('Cannot bind a stream to a disposed Rx');
  late StreamSubscription<T> sub;
  sub = stream.listen((va) => value = va,
      onDone: () => _boundStreams?.remove(sub));
  (_boundStreams ??= <StreamSubscription<T>>{}).add(sub);
  reportAdd(() {
    if (_boundStreams?.remove(sub) ?? false) sub.cancel();
  });
}