ValueSubject<T>.lazy constructor

ValueSubject<T>.lazy(
  1. T initialValue(), {
  2. bool sync = false,
})

Constructs a new ValueSubject with an initial value that is not generated until value is read.

After construction, hasValue will be true and value will return the result of calling the initialValue function.

Note that if add is called before value is read, then initialValue will never be called.

Implementation

factory ValueSubject.lazy(T Function() initialValue, {bool sync = false}) {
  var controller = StreamController<T>.broadcast(sync: sync);
  var currentValue = _CurrentValue<T>(_LazyValue<T>(initialValue));
  return ValueSubject._(controller, currentValue, sync);
}