fetchPaginatedList method
Fetches the next page of the paginated list.
Implementation
@override
void fetchPaginatedList({PaginationRequest? requestOverride, int? limit}) {
// Prevent concurrent fetch operations
if (_isFetching) {
_logger.d('Fetch already in progress, skipping duplicate request');
return;
}
// Check error retry strategy
if (_lastFetchWasError) {
switch (errorRetryStrategy) {
case ErrorRetryStrategy.automatic:
// Allow retry, clear the error flag
_lastFetchWasError = false;
_lastError = null;
break;
case ErrorRetryStrategy.manual:
// Don't retry automatically, require explicit retryAfterError() call
_logger.d('Error retry strategy is manual, skipping automatic retry. Call retryAfterError() to retry.');
return;
case ErrorRetryStrategy.none:
// Don't retry at all
_logger.d('Error retry strategy is none, skipping retry. Call refreshPaginatedList() to reset.');
return;
}
}
// Check if data has expired and reset if necessary
if (checkAndResetIfExpired()) {
// State has been reset to initial, continue to load fresh data
}
if (state is SmartPaginationInitial<T>) {
refreshPaginatedList(requestOverride: requestOverride, limit: limit);
return;
}
if (_hasReachedEnd) return;
// Set isLoadingMore = true when loading more items
final currentState = state;
if (currentState is SmartPaginationLoaded<T>) {
if (currentState.isLoadingMore) return; // Already loading
emit(
currentState.copyWith(
isLoadingMore: true,
loadMoreError: null, // Clear any previous error
),
);
}
final request = _buildRequest(
reset: false,
override: requestOverride,
limit: limit,
);
_fetch(request: request, reset: false);
}