Flutter Firestore paginated query drifts when earlier pages update in real time
0 reputation · 30 Dec 2024, 18:41 UTC
Goal
Bound a large Firestore collection in a Flutter app and page through it using limit() with startAfterDocument(), while keeping a real-time listener active on the initial page.
Constraints
Firestore pagination requires a deterministic ordering field backed by a matching index, and startAfterDocument() depends on that order staying identical between page loads. Real-time listeners do not automatically propagate changes from an earlier page into later pages, and documents deleted between loads can cause skipped or duplicated items. Version assumption: recent stable release of the Flutter Firestore SDK. This behavior requires emulator-based verification before production use.
Questions
- Should the application re-query all subsequent pages whenever a document in an earlier page changes, or merge updates locally?
- How should the last-document snapshot be refreshed when the ordering field of a paginated document is modified?
- What is the recommended strategy for detecting and recovering skipped or duplicated documents after a deletion occurs between page loads?