Skip to content

cloud_firestore needs metadata for QuerySnapshot (in addition to DocumentSnapshots in it) #35550

@gazialankus

Description

@gazialankus

metadata in QuerySnapshot is an existing Firestore feature in other platforms but it's not there in Flutter.

The Flutter cloud_firestore library's QuerySnapshot object needs to provide a metadata field that indicates whether the query result is coming from the cache or the server. The individual DocumentSnapshot objects in QuerySnapshot have this metadata field; however, when the query result is empty, we don't get any DocumentSnapshot objects and we have no idea whether the QuerySnapshot came from the cache (offline) or from the server.

Android and Web already have metadata in QuerySnapshot. I didn't check other platforms.

I was hoping I could fix it myself and provide a PR, however it seems we just don't get that data under the hood. When I set a breakpoint here, I see that data, which is the result of Query#getDocuments has only these fields:

0 = {map entry} "documentChanges" -> [_List]
1 = {map entry} "documents" -> [_List]
2 = {map entry} "metadatas" -> [_List]
3 = {map entry} "paths" -> [_List]

The metadatas field is related to the individual DocumentSnapshots. When the query result is empty, all of these lists are empty as well. Hence the lack of metadata about our query.

It seems this is coming from a platform channel, so definitely it must be using Android Firebase libraries. However, as I said above, Android libraries have metadata for QuerySnapshot but Flutter, which seems to be using the Android libraries through a platform channel does not have it. Is this because the Flutter plugin is using an old version of the Android library?

The current way to add Firebase to Flutter does not have anything about Android Firebase library versions. Only classpath 'com.google.gms:google-services:3.2.1' seems to be a versioned thing, is it what's holding this back? I tried 4.2.0 but it's the same.

Here is a relevant discussion in Slack. I'd appreciate any suggestion.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions