EdsonBueno / infinite_scroll_pagination

Flutter package to help you lazily load and display pages of items as the user scrolls down your screen.
https://pub.dev/packages/infinite_scroll_pagination
MIT License
623 stars 210 forks source link

Problems when returning from RequestListener without change #235

Closed kyi87 closed 6 months ago

kyi87 commented 1 year ago

Hello, in my usecase i have a onSearch-method which refreshs the PagingController after a new searchterm was entered by the user. In the same method i use a dio-canceltoken to cancel the preceeding requests and start a new request by refreshing the controller. So if the preceeding request was canceled, i got a CancelationException which i catch and return from the RequestListener without doing anything, the refreshPage-Method is not called.

After the catch and return the RequestListener doesn't get called anymore and i only see the CircularProgressIndicator spinning. I have no idea how to handle something like that. Do i have to do something with the PagingController after catching and return?

Thanks in advance.

Example:

@override
void initState() {
    _pagingController.addPageRequestListener(_listen);
    super.initState();
  }

 void _listen(pageKey) async {
    try {
      var watchlistResult = await _fetchWatchlist(pageKey, _filter);
      refreshPage(pageKey, watchlistResult);
    }
    on CancelationException catch(e){
      _pagingController.error = null;
      return;    
    } catch (error) {
      _pagingController.error = error;
    }
  }

 void refreshPage(
      int pageNumber, WatchlistCollectionListPagedResponse result) {
    final items = result.data;
    if (items == null) {
      return;
    }

final isLastPage = result.totalPages == pageNumber + 1;
    if (isLastPage) {
      _pagingController.appendLastPage(items);
    } else {
      final nextPageKey = pageNumber + 1;
      _pagingController.appendPage(items, nextPageKey);
    }
  }

void _onSearch(String searchString) async {
    _filter.filterString = searchString;
    _cancelToken.cancel("Abgebrochen");
    _cancelToken = CancelToken();
    _pagingController.refresh();
  }
Tellingdev commented 1 year ago

I have a similar error

clragon commented 6 months ago

setting _pagingController.error = null will not refresh the controller if the error was already null. you can manually request the page again by notifying the page listeners.