【发布时间】:2021-11-02 16:13:56
【问题描述】:
目标
从AsyncSnapshot<QuerySnapshot>获取文档名称
我做了什么
在此集合users 中有许多名称为uid 的文档。
使用FutureBuilder 得到AsyncSnapshot<QuerySnapshot>。
FutureBuilder(
future: FirebaseFirestore.instance
.collection("users")
.where('type', arrayContainsAny: ["Game", "Movie"])
.get(),
builder: (BuildContext context,
AsyncSnapshot<QuerySnapshot> snapshot) {
if (snapshot.hasError) {
return Text(snapshot.error.toString());
}
if (snapshot.connectionState == ConnectionState.done) {
String uid = ...... // Want to get document id (= uid)
通过使用此快照,可以获得每个文档的字段。 但当然这些不包括他们自己的名字。
如何从AsyncSnapshot<QuerySnapshot> 获取文档 ID?
【问题讨论】: