StateSubject<T> constructor

StateSubject<T>(
  1. T seedValue, {
  2. Equality<T>? equals,
  3. void onListen()?,
  4. FutureOr<void> onCancel()?,
  5. bool sync = false,
})

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

seedValue becomes the current value of Subject. equals is used to determine equality between previous data event and current data event.

See also StreamController.broadcast, ValueSubject.

Implementation

factory StateSubject(
  T seedValue, {
  Equality<T>? equals,
  void Function()? onListen,
  FutureOr<void> Function()? onCancel,
  bool sync = false,
}) {
  final controller = StreamController<T>.broadcast(
    onListen: onListen,
    onCancel: onCancel,
    sync: sync,
  );
  return StateSubject._(
    seedValue,
    equals ?? StateStream.defaultEquality,
    controller,
  );
}