Hooshyar
Hooshyar

Reputation: 1270

Disable Firestore cache for a single query

problem: the stream view shows old data for a brief moment. showing old data is useful on other streams, so I don't want to disable it for the entire project, but on one specific screen, it confuses the user.

I'm using Firebase Firestore for a flutter app, I want to disable It’s offline service only on one screen and one stream, not for the entire project, I know how to disable persistence on initialization, but I need to disable it only for a single query.

Upvotes: 0

Views: 1097

Answers (1)

Frank van Puffelen
Frank van Puffelen

Reputation: 598728

You can't listen for a stream in a way that bypasses the local cache. But you can detect in your callback whether a document was instantiated from the cache (and may be stale) by checking the DocumentSnapshot.metadata.isFromCache property. If the isFromCache is false, the snapshot is guaranteed to be up to date with the server.

Upvotes: 2

Related Questions