Infinite Scrolling Pagination in Flutter | raywenderlich.com

Learn how to implement infinite scrolling pagination (also known as lazy loading) in Flutter using the Infinite Scroll Pagination package.


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/14214369-infinite-scrolling-pagination-in-flutter

how to delete an item in the data list please? I mean I have a 100 items displayed, then I want to delete an item at 0 index

Hi @cuong1112035.

You can control what items are shown by using the itemList property of PagingController.
Here’s how your function deleting an item could look like:

final oldList = _pagingController.itemList;
final newList = oldList..removeAt(0);
_pagingController.itemList = newList;

By changing the itemList property, the UI will automatically reflect the changes.

1 Like

setState(() {
final oldList = _pagingController.itemList;
final newList = oldList…removeAt(0);
_pagingController.itemList = newList;
});
It works for me, many thanks

If your widget hierarchy is big, a better alternative than setState would be creating a copy of the old list. Like this:

final oldList = _pagingController.itemList;
final newList = List.of(oldList);
newList.removeAt(0);
_pagingController.itemList = newList;

That way, the only thing rebuilt will be your paged list.

Thank you for the tutorial but many things for beginer level.

1 Like

Hi, is there a way where this can work with page view builder as well?

Great job with the tutorial!
Any suggestions for implementing bidirectional lazy loading based on infinite_scroll_pagination, which seems to be quite a mature package?
Struggling with a calendar application. Obvious use case - start off with today’s entries and scroll back or forward chronologically. Dataset in question currently has 16K+ entries and stretches way back into 2008 and forward into next 2-3 months.

In “paged_article_list_view.dart”, inside initState(), when we call _pagingController.addPageRequestListener((pageKey) {_fetchPage(pageKey);});, what exactly is pageKey and how is it defined?

I believe it is endpoint used to identify pages - similar to firstPageKey. But how is it initialized / defined?