retryAfterError method

void retryAfterError()

Retries the last failed fetch operation.

Use this method when errorRetryStrategy is set to ErrorRetryStrategy.manual to explicitly retry after an error.

Example:

if (cubit.hasError) {
  cubit.retryAfterError();
}

Implementation

void retryAfterError() {
  if (!_lastFetchWasError) {
    _logger.d('retryAfterError called but there is no error to retry');
    return;
  }

  _logger.d('Retrying after error...');
  _lastFetchWasError = false;
  _lastError = null;

  // Determine if this was an initial load or load more
  if (state is SmartPaginationError<T>) {
    // Initial load failed, refresh
    refreshPaginatedList();
  } else if (state is SmartPaginationLoaded<T>) {
    // Load more failed, retry load more
    final currentState = state as SmartPaginationLoaded<T>;
    if (currentState.loadMoreError != null) {
      emit(currentState.copyWith(loadMoreError: null));
      final request = _buildRequest(reset: false);
      _fetch(request: request, reset: false);
    }
  }
}