在这里,我只想从我的消防站获得前十名,我搜索了我如何使用我的列表视图,但我没有到任何地方。所以我想用我的证件来代替。在我的消防站里,我给出了从1到10的前10个文档it,现在我被困住了,我不知道该如何做。请帮帮忙。
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,
)
);
},
);发布于 2022-02-16 12:35:08
您可能正在搜索limit()函数。根据文档
若要限制从查询返回的文档数量,请对集合引用使用限制方法。
您可以这样实现它:
fireStore.collection(path).limit(10).snapshots();发布于 2022-02-16 12:34:57
将您的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://stackoverflow.com/questions/71141603
复制相似问题