ComputedAsyncNotifier<T> constructor

ComputedAsyncNotifier<T>(
  1. Future<T> compute(), {
  2. required List<ChangeNotifier> depends,
  3. void onError(
    1. dynamic error
    )?,
  4. T? beforeUpdate()?,
})

Implementation

ComputedAsyncNotifier(this.compute,
    {required this.depends, this.onError, this.beforeUpdate}) {
  _onChange = oneCallTask(() {
    _loading = true;

    if (beforeUpdate != null) {
      _value = beforeUpdate!();
    }

    _updateValue()
        .then((_) => notifyListeners())
        .catchError((error) => onError?.call(_error = error))
        .whenComplete(() => _loading = false);
  });
}