Reputation: 900
i have a listener for any change happens it works fine but i can't get the type of change is it Delete, Add or modify
Firestore.instance.collection('groups').snapshots().listen((data) {
data.documentChanges.forEach((change) {
print('documentChanges ${change.document.data}');
});
});
Upvotes: 3
Views: 1452
Reputation: 10963
According to this Google Cloud Firestore API documentation, you can access to the type of DocumentChange
with getType()
In case of the Flutter plugin that would be the property type
(you can check the DocumentChange
class of the plugin here: document_change.dart). It contains this enum
for the type
property:
/// An enumeration of document change types. enum DocumentChangeType { /// Indicates a new document was added to the set of documents matching the /// query. added, /// Indicates a document within the query was modified. modified, /// Indicates a document within the query was removed (either deleted or no /// longer matches the query. removed, } /// The type of change that occurred (added, modified, or removed). final DocumentChangeType type;
So in your case you should be able to do:
change.type == DocumentChangeType.added
Upvotes: 4