Back

Pagination examples

  • 0
  • Flutter
Vineet
3 Apr, 2023, 15:45

Does anyone have a properly implemented example code for pagination ? I am thinking of using the cursorAfter and cursorBefore to lazily load the feed data but would be great to get some good examples on how to go about it.

TL;DR
User is looking for examples and guidance on how to implement pagination in a Flutter app using cursor-based pagination. They are considering using the cursorAfter and cursorBefore parameters to lazily load feed data. They receive suggestions for a package called 'infinite_scroll_pagination' and are directed to the API documentation for cursor usage. The user also asks for a properly implemented example code, and a link to an example code on GitHub is provided.
joeyouss
3 Apr, 2023, 16:31

Hi, while I search for examples, gonna leave this here for reference: https://dev.to/appwrite/this-is-why-you-should-use-cursor-pagination-4nh5

joeyouss
3 Apr, 2023, 16:32
Vineet
4 Apr, 2023, 01:47

I'll check it out. Thanks Jyoti

Vineet
4 Apr, 2023, 02:03

@joeyouss Shouldn't this example return all the documents ?

TypeScript
      return [
        ...response.documents,
        ...(await getAllPages(collectionId, queries, nextCursor))
      ]
    }

The await function will keep executing till it finds all the documents. How would it be different than listing the entire collection at once ?

Drake
4 Apr, 2023, 03:43

That's a recursive function that calls itself until it fetches all pages so there are multiple API calls to get all the data

Vineet
4 Apr, 2023, 03:48

True but from what i understand, it will recursively call till it fetches all the documents from the collection right and finally returns an entire array of it ? This does not look not like it is being lazily loaded for infinitely scrolling a feed.

Drake
4 Apr, 2023, 03:49

No it is not, but perhaps it shows you how to use the cursor

Drake
4 Apr, 2023, 03:51

The rest depends on your front end. You would make another list documents API call when you're towards the end of your list

Vineet
4 Apr, 2023, 03:52

thanks for clarifying, the api documentation covers the cursor usage well. I was just wondering how we would actually implement it in a flutter app. If i wanted to fetch all documents, i would just listDocuments the entire collection though.

Drake
4 Apr, 2023, 03:53
Drake
4 Apr, 2023, 03:54

I'm pretty sure I've also seen tutorials online for how to implement infinite scrolling.

Drake
4 Apr, 2023, 03:55

The general idea is all the same..once the user reaches the end or as they get close to the end, fetch more data

Vineet
4 Apr, 2023, 04:01

This sounds interesting. I'll check it out, thanks !

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more