Home > other >  Flutter Firestore endBeforeDocument doesn't work
Flutter Firestore endBeforeDocument doesn't work

Time:02-22

await FirebaseFirestore.instance
      .collection('NewCardsList')
      .orderBy('timestamp')
      .endBeforeDocument(oldestDocID)
      .limitToLast(_theNumberOfFetchingOldCard)
      .get()
      .then(...);

I made this code 3-4month ago and it worked well.

However it suddenly doesn't work...

I'm checking the code with breakpoint with every single line and there is no reaction after ".then() line". (Does not go to the next line)

And I found that it works well if I remove ".endBeforeDocument() method".

      DocumentSnapshot oldestDocID = await FirebaseFirestore.instance
      .collection('NewCardsList')
      .doc(cardManagementProvider.newCardsIDList.last)
      .get();
  print('############# ${oldestDocID.id}');

This code is for getting DocumentSnapshot in ".endBeforeDocument() method".

I could see correct result with print() to see DocumentSnapshot.

Please give me some comment about this problem.

CodePudding user response:

maybe you should just use afterAt

CodePudding user response:

I solved it after changing logic with startAfterDocument().

But I still cannot understand why it does not work with endBeforeDocument()

await FirebaseFirestore.instance
      .collection('NewCardsList')
      .orderBy('timestamp', descending: true)
      .startAfterDocument(oldestDocID)
      .limit(_theNumberOfFetchingOldCard)
      .get()
      .then(...);
  • Related