fetch method

void fetch()

Implementation

void fetch() {
  // Don't start fetch if it is cancelled or is fetching
  if (isCancelled || fetching || isCached) return;

  dispatchFetch();

  snapshot = const AsyncSnapshot.waiting();
  future = query();
  notifyListeners();
  future?.then((result) {
    if (!isCancelled) {
      update(AsyncSnapshot.withData(ConnectionState.done, result));
      dispatchComplete();
      notifyListeners(); // Notify listeners after the update
    }
  }).catchError((error) {
    if (!isCancelled) {
      update(AsyncSnapshot.withError(ConnectionState.done, error));
      dispatchError();
      notifyListeners(); // Notify listeners after the update
    }
  }).whenComplete(() {
    markAsComplete();
  });
}