I'm saving some posts on Firestore with a timestamp property and then I query this posts ordered by timestamp. I'm trying to create a "loadMore" function then works when the user scrolls to bottom and loads more posts.
I'm saving the posts this way:
Firestore.instance
  .collection('posts')
  .add(<String, dynamic> {
     'content': 'content,
     'likes': 0,
     'comments': 0,
     'timestamp': DateTime.now(),
   })
And trying to query this way:
Firestore.instance
  .collection('posts')
  .orderBy('timestamp', descending: true)
  .startAfter(
    []..add(posts.last.timestamp)
  )
  ..limit(5)
But, it keeps ignoring the "startAfter" and returning me a list starting with the first element of the collection and not with the next ones.
Would love to get help using this type of query :)
Convert the DateTime to Unix date-time
'timestamp': DateTime.now().toUtc().millisecondsSinceEpoch
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With