ValueStreamController<T> constructor

ValueStreamController<T>({
  1. T? initialValue,
  2. bool initiallyNull = false,
})

Create a new ValueStreamController with an optional initial value.

initialValueIsNull must be set to true, if the initial value is null. This ensures that the Stream emits a null value when a listener subscribes.

Implementation

ValueStreamController({
  T? initialValue,
  bool initiallyNull = false,
}) : _controller = StreamController<T>.broadcast() {
  if (initialValue != null || initiallyNull) {
    _lastValue = initialValue;
    _hasValue = true;
  }

  _controller.onListen = () => onListen?.call();
  _controller.onCancel = () => onCancel?.call();
}