目標
從中獲取檔案名稱 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)
通過使用此快照,可以獲取每個檔案的欄位。但當然這些不包括他們自己的名字。
如何從中獲取檔案 ID AsyncSnapshot<QuerySnapshot>?
uj5u.com熱心網友回復:
snapshot.data!.docs可以包含零個、1 個或多個符合條件的檔案。這是檔案快照串列。
例如,第一個結果可以在snapshot.data!docs[0]. 從這里獲取檔案 ID(在您的情況下為 uid)只需使用snapshot.data!docs[0].id.
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/345324.html
上一篇:顫振:如何使用型別或泛型來映射?
