Flutter Firestore pagination

There is an error here:

     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.

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 attrubutes, itemBuilder 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'),
      )