BehaviorSubject<T> constructor

BehaviorSubject<T>({
  1. void onListen()?,
  2. void onCancel()?,
  3. bool sync = false,
})

Constructs a BehaviorSubject, optionally pass handlers for onListen, onCancel and a flag to handle events sync.

See also StreamController.broadcast

Implementation

factory BehaviorSubject({
  void Function()? onListen,
  void Function()? onCancel,
  bool sync = false,
}) {
  // ignore: close_sinks
  final controller = StreamController<T>.broadcast(
    onListen: onListen,
    onCancel: onCancel,
    sync: sync,
  );

  final wrapper = _Wrapper<T>();

  return BehaviorSubject<T>._(controller, Rx.defer<T>(_deferStream(wrapper, controller, sync), reusable: true), wrapper);
}