@@ -203,6 +203,10 @@ static FIRFirestoreSource getSource(NSDictionary *arguments) {
203203 @" documentChanges" : documentChanges,
204204 @" documents" : documents,
205205 @" metadatas" : metadatas,
206+ @" metadata" : @{
207+ @" hasPendingWrites" : @(snapshot.metadata .hasPendingWrites ),
208+ @" isFromCache" : @(snapshot.metadata .isFromCache ),
209+ }
206210 };
207211}
208212
@@ -522,39 +526,52 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result
522526 message: [exception name ]
523527 details: [exception reason ]]);
524528 }
529+ NSNumber *includeMetadataChanges = call.arguments [@" includeMetadataChanges" ];
525530 id <FIRListenerRegistration> listener = [query
526- addSnapshotListener: ^(FIRQuerySnapshot *_Nullable snapshot, NSError *_Nullable error) {
527- if (snapshot == nil ) {
528- result (getFlutterError (error));
529- return ;
530- }
531- NSMutableDictionary *arguments = [parseQuerySnapshot (snapshot) mutableCopy ];
532- [arguments setObject: handle forKey: @" handle" ];
533- [weakSelf.channel invokeMethod: @" QuerySnapshot" arguments: arguments];
534- }];
531+ addSnapshotListenerWithIncludeMetadataChanges: includeMetadataChanges.boolValue
532+ listener: ^(FIRQuerySnapshot *_Nullable snapshot,
533+ NSError *_Nullable error) {
534+ if (snapshot == nil ) {
535+ result (getFlutterError (error));
536+ return ;
537+ }
538+ NSMutableDictionary *arguments =
539+ [parseQuerySnapshot (snapshot) mutableCopy ];
540+ [arguments setObject: handle forKey: @" handle" ];
541+ [weakSelf.channel invokeMethod: @" QuerySnapshot"
542+ arguments: arguments];
543+ }];
535544 _listeners[handle] = listener;
536545 result (handle);
537- } else if ([@" Query#addDocumentListener " isEqualToString: call.method]) {
546+ } else if ([@" DocumentReference#addSnapshotListener " isEqualToString: call.method]) {
538547 __block NSNumber *handle = [NSNumber numberWithInt: _nextListenerHandle++];
539548 FIRDocumentReference *document = getDocumentReference (call.arguments );
540- id <FIRListenerRegistration> listener =
541- [document addSnapshotListener: ^(FIRDocumentSnapshot *snapshot, NSError *_Nullable error) {
542- if (snapshot == nil ) {
543- result (getFlutterError (error));
544- return ;
545- }
546- [weakSelf.channel invokeMethod: @" DocumentSnapshot"
547- arguments: @{
548- @" handle" : handle,
549- @" path" : snapshot ? snapshot.reference .path : [NSNull null ],
550- @" data" : snapshot.exists ? snapshot.data : [NSNull null ],
551- @" metadata" : snapshot ? @{
552- @" hasPendingWrites" : @(snapshot.metadata .hasPendingWrites ),
553- @" isFromCache" : @(snapshot.metadata .isFromCache ),
554- }
555- : [NSNull null ],
556- }];
557- }];
549+ NSNumber *includeMetadataChanges = call.arguments [@" includeMetadataChanges" ];
550+ id <FIRListenerRegistration> listener = [document
551+ addSnapshotListenerWithIncludeMetadataChanges: includeMetadataChanges.boolValue
552+ listener: ^(FIRDocumentSnapshot *snapshot,
553+ NSError *_Nullable error) {
554+ if (snapshot == nil ) {
555+ result (getFlutterError (error));
556+ return ;
557+ }
558+ [weakSelf.channel
559+ invokeMethod: @" DocumentSnapshot"
560+ arguments: @{
561+ @" handle" : handle,
562+ @" path" : snapshot ? snapshot.reference .path
563+ : [NSNull null ],
564+ @" data" : snapshot.exists ? snapshot.data
565+ : [NSNull null ],
566+ @" metadata" : snapshot ? @{
567+ @" hasPendingWrites" :
568+ @(snapshot.metadata .hasPendingWrites ),
569+ @" isFromCache" :
570+ @(snapshot.metadata .isFromCache ),
571+ }
572+ : [NSNull null ],
573+ }];
574+ }];
558575 _listeners[handle] = listener;
559576 result (handle);
560577 } else if ([@" Query#getDocuments" isEqualToString: call.method]) {
@@ -577,7 +594,7 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result
577594 }
578595 result (parseQuerySnapshot (snapshot));
579596 }];
580- } else if ([@" Query# removeListener" isEqualToString: call.method]) {
597+ } else if ([@" removeListener" isEqualToString: call.method]) {
581598 NSNumber *handle = call.arguments [@" handle" ];
582599 [[_listeners objectForKey: handle] remove ];
583600 [_listeners removeObjectForKey: handle];
0 commit comments