[英]Flutter - Snapshot from Sub-collection
I was reading several answers here but I could not get better understanding to solve my issue which is the following... I don't know how to get the "docId" in the code below... I want to query a sub-collection " People " as snapshot for the stream method which I will listen using Bloc... I am not able to understand how to get the docId.我在这里阅读了几个答案,但我无法更好地理解解决以下问题的方法......我不知道如何在下面的代码中获取“docId” ......我想查询一个子 -集合“ People ”作为我将使用 Bloc 收听的流方法的快照...我无法理解如何获取 docId。 Anyone could help me with this?任何人都可以帮助我吗?
Thanks谢谢
Stream<People> statusMember({required String email}) {
var user = auth.FirebaseAuth.instance.currentUser;
final snap = _firestore
.collection('users')
.doc(user!.email)
.collection('people') //sub-collection
.doc(docId) // docId as reference? How to get it?
.snapshots()
.map((snapshot) => People.fromSnapshot(snapshot)); // model
print(snap);
return snap;
}
By digging more into the Firebase documentation, it is not possible to read docs in a sub-collection the way I wanted.通过深入研究 Firebase 文档,无法按照我想要的方式阅读子集合中的文档。 Therefore, I've changed my approach and the code looks like this:因此,我改变了方法,代码如下所示:
Stream<People?> statusMember({required String email}) {
var user = auth.FirebaseAuth.instance.currentUser;
final snap = _firestore
.collection('users')
.doc(user!.email)
.collection('people')
.where('email', isEqualTo: email)
.snapshots()
.map(
(snappshot) {
for (var doc in snappshot.docs) {
return People.fromSnapshot(doc);
}
},
);
print(snap);
return snap;
}
it is working as expected.它按预期工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.