如何解决在ListView.builder中定义从Firestore检索到的文档数
我正在开发我的应用程序,并从Firestore的Documents集合中检索数据。 每次用户通过表单字段添加时,都会建立一个列表,但是什么用作itemCount?目前,我只输入3,但我想每次生成另一个列表 这是我的代码
Widget build(BuildContext context) {
return StreamBuilder(
stream: getData(),builder: (context,snapshot) {
if (!snapshot.hasData) return Text('Loading data please Wait');
return Column(
children: <Widget>[
Container(
height: 350,child: ListView.builder(
shrinkWrap: true,itemCount: 3,itemBuilder: (BuildContext context,int index) {
return Card(
color: Color(0xFF1f2032),elevation: 15,child: Container(
width: 60,height: 60,child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,children: <Widget>[
Card(
color: Color(0xfffeaf0d),child: Container(
height: 40,width: 40,child: Icon(
Icons.local_shipping,color: Colors.white,size: 25,)),),Text(
snapshot.data['phone'],.....
解决方法
由于您要从Firestore中检索文档,因此在itemCount
内,您需要使用以下内容:
itemCount: snapshot.data.documents.length,
documents
属性将返回集合中的文档列表,而length
将为您提供此列表中的对象数量。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。