diff --git a/packages/cloud_firestore/CHANGELOG.md b/packages/cloud_firestore/CHANGELOG.md index 3d68c9afe1e5..f6f2e143f416 100644 --- a/packages/cloud_firestore/CHANGELOG.md +++ b/packages/cloud_firestore/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.12.8+1 + +* Add `metadata` to `QuerySnapshot`. + ## 0.12.8 * Updated how document ids are generated to more closely match native implementations. diff --git a/packages/cloud_firestore/android/src/main/java/io/flutter/plugins/firebase/cloudfirestore/CloudFirestorePlugin.java b/packages/cloud_firestore/android/src/main/java/io/flutter/plugins/firebase/cloudfirestore/CloudFirestorePlugin.java index 5254b8b1493d..0c3496b547fe 100644 --- a/packages/cloud_firestore/android/src/main/java/io/flutter/plugins/firebase/cloudfirestore/CloudFirestorePlugin.java +++ b/packages/cloud_firestore/android/src/main/java/io/flutter/plugins/firebase/cloudfirestore/CloudFirestorePlugin.java @@ -192,6 +192,11 @@ private Map parseQuerySnapshot(QuerySnapshot querySnapshot) { } data.put("documentChanges", documentChanges); + Map metadata = new HashMap<>(); + metadata.put("hasPendingWrites", querySnapshot.getMetadata().hasPendingWrites()); + metadata.put("isFromCache", querySnapshot.getMetadata().isFromCache()); + data.put("metadata", metadata); + return data; } diff --git a/packages/cloud_firestore/example/test_driver/cloud_firestore.dart b/packages/cloud_firestore/example/test_driver/cloud_firestore.dart index d7d85db5b000..5cad0386e6b8 100644 --- a/packages/cloud_firestore/example/test_driver/cloud_firestore.dart +++ b/packages/cloud_firestore/example/test_driver/cloud_firestore.dart @@ -51,6 +51,7 @@ void main() { .where('message', isEqualTo: 'Hello world!') .limit(1); final QuerySnapshot querySnapshot = await query.getDocuments(); + expect(querySnapshot.metadata, isNotNull); expect(querySnapshot.documents.first['message'], 'Hello world!'); final DocumentReference firstDoc = querySnapshot.documents.first.reference; @@ -70,6 +71,7 @@ void main() { .limit(1); final QuerySnapshot querySnapshot = await query.getDocuments(); expect(querySnapshot.documents.first['stars'], 5); + expect(querySnapshot.metadata, isNotNull); }); test('increment', () async { diff --git a/packages/cloud_firestore/ios/Classes/CloudFirestorePlugin.m b/packages/cloud_firestore/ios/Classes/CloudFirestorePlugin.m index a18c809d4098..10ecc55a4335 100644 --- a/packages/cloud_firestore/ios/Classes/CloudFirestorePlugin.m +++ b/packages/cloud_firestore/ios/Classes/CloudFirestorePlugin.m @@ -203,6 +203,10 @@ static FIRFirestoreSource getSource(NSDictionary *arguments) { @"documentChanges" : documentChanges, @"documents" : documents, @"metadatas" : metadatas, + @"metadata" : @{ + @"hasPendingWrites" : @(snapshot.metadata.hasPendingWrites), + @"isFromCache" : @(snapshot.metadata.isFromCache), + } }; } diff --git a/packages/cloud_firestore/lib/src/query_snapshot.dart b/packages/cloud_firestore/lib/src/query_snapshot.dart index 4cc85403e19f..1ecb0bd54fe1 100644 --- a/packages/cloud_firestore/lib/src/query_snapshot.dart +++ b/packages/cloud_firestore/lib/src/query_snapshot.dart @@ -25,7 +25,11 @@ class QuerySnapshot { data['documentChanges'][index], _firestore, ); - }); + }), + metadata = SnapshotMetadata._( + data['metadata']['hasPendingWrites'], + data['metadata']['isFromCache'], + ); /// Gets a list of all the documents included in this snapshot final List documents; @@ -34,5 +38,7 @@ class QuerySnapshot { /// is the first snapshot, all documents will be in the list as Added changes. final List documentChanges; + final SnapshotMetadata metadata; + final Firestore _firestore; } diff --git a/packages/cloud_firestore/pubspec.yaml b/packages/cloud_firestore/pubspec.yaml index 9fa89bfe045e..1c43c3fd018e 100755 --- a/packages/cloud_firestore/pubspec.yaml +++ b/packages/cloud_firestore/pubspec.yaml @@ -3,7 +3,7 @@ description: Flutter plugin for Cloud Firestore, a cloud-hosted, noSQL database live synchronization and offline support on Android and iOS. author: Flutter Team homepage: https://github.com/flutter/plugins/tree/master/packages/cloud_firestore -version: 0.12.8 +version: 0.12.8+1 flutter: plugin: diff --git a/packages/cloud_firestore/test/cloud_firestore_test.dart b/packages/cloud_firestore/test/cloud_firestore_test.dart index 2b679fea6d0b..92173085c24c 100755 --- a/packages/cloud_firestore/test/cloud_firestore_test.dart +++ b/packages/cloud_firestore/test/cloud_firestore_test.dart @@ -63,6 +63,7 @@ void main() { 'paths': ["${methodCall.arguments['path']}/0"], 'documents': [kMockDocumentSnapshotData], 'metadatas': >[kMockSnapshotMetadata], + 'metadata': kMockSnapshotMetadata, 'documentChanges': [ { 'oldIndex': -1, @@ -105,6 +106,7 @@ void main() { 'paths': ["${methodCall.arguments['path']}/0"], 'documents': [kMockDocumentSnapshotData], 'metadatas': >[kMockSnapshotMetadata], + 'metadata': kMockSnapshotMetadata, 'documentChanges': [ { 'oldIndex': -1, @@ -614,6 +616,10 @@ void main() { test('getDocumentsFromCollection', () async { QuerySnapshot snapshot = await collectionReference.getDocuments(source: Source.server); + expect(snapshot.metadata.hasPendingWrites, + equals(kMockSnapshotMetadata['hasPendingWrites'])); + expect(snapshot.metadata.isFromCache, + equals(kMockSnapshotMetadata['isFromCache'])); DocumentSnapshot document = snapshot.documents.first; expect(document.documentID, equals('0')); expect(document.reference.path, equals('foo/0')); @@ -781,6 +787,10 @@ void main() { }); test('getDocumentsFromCollectionGroup', () async { QuerySnapshot snapshot = await collectionGroupQuery.getDocuments(); + expect(snapshot.metadata.hasPendingWrites, + equals(kMockSnapshotMetadata['hasPendingWrites'])); + expect(snapshot.metadata.isFromCache, + equals(kMockSnapshotMetadata['isFromCache'])); DocumentSnapshot document = snapshot.documents.first; expect(document.documentID, equals('0')); expect(document.reference.path, equals('bar/0'));