fetch method

Future<void> fetch({
  1. bool isQuiet = false,
})

Fetch data by calling onFetch Set isQuiet = true to avoid rendering loading state, default false.

Implementation

Future<void> fetch({bool isQuiet = false}) async {
  _error = null;
  _isLoading = true;
  if (_isMounted && !isQuiet) notifyListeners();

  try {
    final result = await onFetch();
    _data = result;
    if (_awaitListener) {
      await onFetchCompleted(result);
    } else {
      onFetchCompleted(result);
    }
  } catch (e) {
    _error = e;
    if (_awaitListener) {
      await onFetchFailed(e);
    } else {
      onFetchFailed(e);
    }
  }

  _isLoading = false;
  if (_isMounted) notifyListeners();
}