updateDataAsync method

Future<void> updateDataAsync(
  1. FutureOr<T> fetchData()
)

Updates the data of this notifier asynchronously using the data returned by the provided function, and then returns a Future that can optionally be used to await the completion of the update.

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).

Note that the returned Future will never complete with an error.

Instead of using the Future returned by this method, consider using future instead, which will await the next successful data or error result of this notifier.

Implementation

Future<void> updateDataAsync(FutureOr<T> Function() fetchData) async {
  await setResultAsync(() async => Data(await fetchData()));
}