fetchMore method
Fetch the next page of data
Implementation
void fetchMore() async {
if (state is PaginatedCleanSuccess<T, E>) {
final currentState = state as PaginatedCleanSuccess<T, E>;
if (currentState.isLoadingMore || !hasNextPage) return;
safeEmit(currentState.copyWith(
isLoadingMore: true,
));
final response = await remoteCall(nextParams).run();
safeEmit(response.match(
(error) {
return currentState.copyWith(
isLoadingMore: false,
);
},
(paginatedResponse) {
updatePagination(paginatedResponse);
return currentState.copyWith(
data: [
...currentState.data,
...paginatedResponse.data,
].toList(),
hasReachedMax: !hasNextPage,
isLoadingMore: false,
);
},
));
}
}