Flutter Pagination on click of a "next page" button

Viewed 281

I know how to implement flutter pagination with an infinite scroll, we just keep storing the lastDocument (last fetched document), and whenever we reach the end of the list while scrolling, we again call the fetchData function which will return the data starting after the lastDocument.

NOTE: I am using firebase firestore to fetch and store data. So, I will use the firestore query startAfterDocument, where we'll pass the last document received.

But what I want to implement is something like this,

enter image description here

Here, the problem is whenever I will tap on the "next" button or on a specific numbered button, for example, from page 1 directly to page 10. We can't store the last document of the first page while getting the data for the 10th page. We would want the last document of the 9th page first, to be able to fetchData for the 10th page.

So, I don't think this is the correct approach, as we will have to fetch the data of 8 extra pages before fetching data for the 10th page.

How should one implement something like this?

1 Answers

I searched for this, it's a nice question by the way.

Once check this

Related