requestNextPageData method

void requestNextPageData()

Implementation

void requestNextPageData() {
  final providerPageKey = _pagingBuilderController.getProviderKey();
  final provider = pagingControllerProvider(providerPageKey);
  final asyncPagingState = ref.read(provider);
  WidgetsBinding.instance.addPostFrameCallback((_) async {
    try {
      var data = await widget.pagingDataController.requestData(asyncPagingState.nextPageKey);
      if (!mounted) return;
      if (needDropNextPageRequest) {
        needDropNextPageRequest = false;
        return;
      }

      if (data.error != null) {
        ref.read(pagingControllerProvider(providerPageKey).notifier).loadError(data.error);
      } else if ((asyncPagingState.itemList?.length ?? 0) > 0 && data.nextPageKey == null) {
        ref.read(pagingControllerProvider(providerPageKey).notifier).appendLastPage((data.itemList ?? []) as List<T>);
      } else {
        ref
            .read(pagingControllerProvider(providerPageKey).notifier)
            .appendPage((data.itemList ?? []) as List<T>, data.nextPageKey);
      }
    } catch (e) {
      ref.read(pagingControllerProvider(providerPageKey).notifier).loadError(e);
    }
    _hasRequestedNextPage = false;
  });
}