fetchMore method

void fetchMore()

Fetch the next page of data

Implementation

void fetchMore() async {
  if (state is PaginatedCleanSuccess<T>) {
    final currentState = state as PaginatedCleanSuccess<T>;
    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(),
          isLoadingMore: false,
        );
      },
    ));
  }
}