How to Do Pagination In FireStore Flutter ??

· 2 min read
How to Do Pagination In FireStore Flutter
How to Do Pagination In FireStore Flutter

Earlier we have been through how to Print Firestore Timestamp as Formatted Date and Time in flutter. So in this article, we will focus on How to Do Pagination In FireStore Flutter.

How to Do Pagination In FireStore Flutter ??

User can fire a query like the below:

Firestore.instance.collection('user').where('name', isEqualTo: 'Tom').orderBy('age').startAfter(_lastDocument).limit(1).getDocuments().then((snapshot) {
         snapshot.documents.forEach((snap) {
            print(snap.data);
          });
         });

startAfter method expects a List value params and you are passing a DocumentSnapshot.

Takes a list of [values], creates and returns a new [Query] that starts after the provided fields relative to the order of the query.

So you could try something like this:

Firestore.instance.collection('user').where('name', isEqualTo: 'Tom').orderBy('age').startAfter([{'name': 'Tom'}]).limit(1).getDocuments().then((snapshot) {
        snapshot.documents.forEach((snap) {
           print(snap.data);
         });
        });

Paginate just with 2 attributes, item builder and query using this package – paginate_firestore

For Example,

PaginateFirestore(
     itemBuilder: (context, documentSnapshot) => ListTile(
       leading: CircleAvatar(child: Icon(Icons.person)),
       title: Text(documentSnapshot.data['name']),
       subtitle: Text(documentSnapshot.documentID),
     ),
     // orderBy is compulsary to enable pagination
     query: Firestore.instance.collection('users').orderBy('name'),
   )

Conclusion:

Thanks for being with us on a Flutter Journey !!! Let me know in the comments if you need any kind of assistance in Flutter development.

So up next you’ll come across articles like pagination in flutter, streambuilder, on a scroll, cloud firestore, firestore limit query, in firestore android, etc.

Keep Learning !!! Keep Fluttering !!!

So in this article, we have been through how to Do Pagination in FireStore flutter.

Drop us your valuable suggestion/feedback to serve you better.

FlutterAgency.com is our portal Platform dedicated to Flutter Technology and Flutter Developers. The portal is full of cool resources from Flutter like Flutter Widget GuideFlutter ProjectsCode libs and etc.

FlutterAgency.com is one of the most popular online portals dedicated to Flutter Technology and daily thousands of unique visitors come to this portal to enhance their knowledge of Flutter.

Leave a Reply