gpt4 book ai didi

firebase - 如何在Flutter中使用Cloud Firestore知道DocumentChange的更改类型

转载 作者:行者123 更新时间:2023-12-03 02:50:39 25 4
gpt4 key购买 nike

我有一个侦听器,可以进行任何更改,但工作正常,但是我无法获取更改的类型,即删除,添加或修改

Firestore.instance.collection('groups').snapshots().listen((data) {
data.documentChanges.forEach((change) {
print('documentChanges ${change.document.data}');
});
});

最佳答案

根据此Google Cloud Firestore API documentation,您可以使用DocumentChange访问getType()的类型

如果是Flutter插件,它将是type属性(您可以在此处检查插件的DocumentChange类:document_change.dart)。它包含enum属性的type:

/// 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;


因此,在您的情况下,您应该能够:
change.type == DocumentChangeType.added

关于firebase - 如何在Flutter中使用Cloud Firestore知道DocumentChange的更改类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58369882/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com