Computed<T> constructor

Computed<T>(
  1. T _compute(), {
  2. T? initialValue,
  3. String? debugLabel,
  4. bool equals(
    1. T a,
    2. T b
    )?,
  5. T guard(
    1. T current,
    2. T next
    )?,
  6. VoidCallback? onListen,
  7. VoidCallback? onCancel,
})

Creates a computed signal with automatic dependency tracking.

The compute function is called lazily when the value is accessed and there are active listeners. Dependencies are detected automatically.

Optionally provide initialValue to defer the first computation.

Implementation

Computed(
  this._compute, {
  T? initialValue,
  this.debugLabel,
  super.equals,
  super.guard,
  VoidCallback? onListen,
  VoidCallback? onCancel,
})  : _userOnListen = onListen,
      _userOnCancel = onCancel,
      // Use a temporary placeholder that will be immediately overwritten
      super(initialValue ?? _computeInitial(_compute)) {
  _cachedValue = value;
  _isStale = false;
}