retryLastFailedRequest method

Future<void> retryLastFailedRequest(
  1. WidgetRef ref
)

Retry the last failed request.

Implementation

Future<void> retryLastFailedRequest(WidgetRef ref) async {
  // Indicate that a new request is in progress
  PagingDataControllerInterface pagingDataControllerInterface =
      ref.read(pagingControllerProvider(pagingDataController.getProviderKey()).notifier);
  ref.read(pagingControllerProvider(pagingDataController.getProviderKey()).notifier).onGoing();
  pagingDataControllerInterface.onGoing();

  var nextPageKey = ref.read(pagingControllerProvider(pagingDataController.getFirstDataPageKey())).nextPageKey;
  try {
    // Retry retrieving the data for the next page
    var data = await pagingDataController.retryLastFailedRequest(nextPageKey);

    // Append data if successful, otherwise load error
    if (data.error == null) {
      pagingDataControllerInterface.appendPage(data.itemList as List<T>, data.nextPageKey);
    } else {
      pagingDataControllerInterface.loadError(data.error);
    }
  } catch (e) {
    pagingDataControllerInterface.loadError(e);
  }
}