setDataAsync method
Sets the data of this notifier asynchronously using the data returned by the provided function, which in turn is returned by this method (in form of a Future).
Remember to always handle the Future
returned by this method. If a return value is not needed, consider using
updateDataAsync instead.
Before executing the provided function, the current state will be set to Loading. When the function returns, the value will be set to Data if successful, or Error if an error occurs (i.e. if the function throws an exception). If this notifier was cancelled during the asynchronous gap, the result of the function call will be ignored and an (Future.error) will be returned by this method (i.e. CancelledException).
Implementation
Future<T> setDataAsync(FutureOr<T> Function() fetchData) async {
return setResultAsync(() async => Data(await fetchData()))
.then((r) => r.isError ? throw (r as Error).error : r.data!);
}