AsyncComputed<T> constructor

AsyncComputed<T>(
  1. Future<T> _getValue(), {
  2. T? defaultValue,
  3. T? beforeUpdate()?,
  4. bool notifyBeforeUpdate = true,
  5. void onError(
    1. dynamic error
    )?,
  6. dynamic immediate = false,
})

Creates an instance of AsyncComputed with the given async function.

  • getValue: The function that fetches the computed value asynchronously.
  • defaultValue: A default value before the async computation completes.
  • beforeUpdate: A function to set a temporary value before computation.
  • notifyBeforeUpdate: If true, notifies listeners when beforeUpdate sets a new value.
  • onError: Callback function for handling errors during async computation.
  • immediate: If true, starts the async computation immediately upon creation.

Implementation

AsyncComputed(this._getValue,
    {T? defaultValue,
    this.beforeUpdate,
    this.notifyBeforeUpdate = true,
    this.onError,
    immediate = false}) {
  _value = defaultValue;
  if (immediate) _runDry();
}