在這里,我試圖僅從我的 firebase firestore 中獲取前 10 個名稱,并且我搜索了如何使用我擁有的串列視圖來做到這一點,但我一無所獲。所以我考慮改為獲取我的檔案的 ID。在我的 Firestore 中,我給出了從 1 到 10 的前 10 個檔案 ID,現在我被卡住了,我不知道該怎么做。請幫忙。
static int id = 1;
StreamBuilder<QuerySnapshot>(
stream: fireStore.collection(path).snapshots(),
builder: (context, snapshot) {
if(!snapshot.hasData){
return Center(
child: CircularProgressIndicator(
backgroundColor: Colors.blueAccent,
),
);
}
List<InfoBox> ancients = [];
try {
final collection = snapshot.data!.docs;
for (var collect in collection) {
final name = collect['Name'];
final image = collect['Image'];
final collectionWidget = InfoBox(
ancientName: name,
ancientImage: image
);
ancients.add(collectionWidget);
}
}catch(e){
print('problems in stream builder \n error : $e');
}
return Expanded(
child:ListView(
children: ancients,
)
);
},
);
uj5u.com熱心網友回復:
您可能正在尋找limit()功能。根據檔案:
要限制從查詢回傳的檔案數量,請在集合參考上使用 limit 方法
你可以像這樣實作它:
fireStore.collection(path).limit(10).snapshots();
uj5u.com熱心網友回復:
如果其他一切正常并且您正在串列中獲取資料,則將您的 ListView 更改為此串列,那么這將起作用。
ListView.builder(
itemCount: ancients.length,
itemBuilder: (BuildContext context, int index) {
return ListTile(
leading: new Image.network(ancients[index].ancientImage),
title: new Text(ancients[index].ancientName),
)
},
)
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/425733.html
上一篇:我怎樣才能分開這兩個值
