Flutter - 如何获取随机文档的特定 ID
Flutter - How to get a specific ID of a random document
正如您在图片中看到的,集合 'Communities' 中包含多个文档,我通过应用以下代码行设法读取了其中的所有数据:
late QuerySnapshot Comms = await _firestore.collection('User').doc(User.userID).collection("Communities").get();
然后将其应用于所需的字段
Text( Comms.docs[index].get("nameOfCommunity").toString(),),
但是我如何才能获得我从中获取数据的集合的 ID?
Firestore 在文档快照上提供了一个名为 id
的 属性,您可以像这样访问它
comms.docs[index].id
检查此引用 link
正如您在图片中看到的,集合 'Communities' 中包含多个文档,我通过应用以下代码行设法读取了其中的所有数据:
late QuerySnapshot Comms = await _firestore.collection('User').doc(User.userID).collection("Communities").get();
然后将其应用于所需的字段
Text( Comms.docs[index].get("nameOfCommunity").toString(),),
但是我如何才能获得我从中获取数据的集合的 ID?
Firestore 在文档快照上提供了一个名为 id
的 属性,您可以像这样访问它
comms.docs[index].id
检查此引用 link