[英]Class 'List<DocumentSnapshot>' has no instance method 'call' in Flutter
My firestore database looks something like this我的 firestore 数据库看起来像这样
What I am trying to do is, I am making a Future list of all the documents with the same uid and then making a ListView using FutureBuilder.我想要做的是,我正在制作一个包含具有相同 uid 的所有文档的 Future 列表,然后使用 FutureBuilder 制作一个 ListView。
The part giving me the error is,给我错误的部分是,
body: FutureBuilder(
future: listBuilder(),
builder: (context, snapshot) {
if(snapshot.hasData == null){
return Container();
}
return ListView(
padding: const EdgeInsets.only(top: 20.0),
children: snapshot.data((data) => _buildListItem(context, data)).toList(),
);
},
),
Future listBuilder() async {
final FirebaseUser user = await FirebaseAuth.instance.currentUser();
final String uid = user.uid;
List<DocumentSnapshot> list = [];
Firestore.instance
.collection('entries')
.where("uid", isEqualTo: uid)
.snapshots()
.listen((data) => data.documents.forEach((doc) => list.add(doc)));
print("------------------------------------------------------------------");
return list;
}
Widget _buildListItem(BuildContext context, DocumentSnapshot snapshot) {
return Container(
padding: const EdgeInsets.symmetric(horizontal: 16.0),
child: InkWell(
child: Row(
children: <Widget>[
Expanded(
child: ListTile(
leading: Text(
snapshot.data['type'],
style: TextStyle(
fontSize: 30,
),
),
title: Text(snapshot.data['description'],
style: TextStyle(
fontSize: 30,
)),
subtitle: Text(snapshot.data['time'].toDate().toString(),
style: TextStyle(
fontSize: 15,
)),
trailing: Text(snapshot.data['value'].toString(),
style: TextStyle(
fontSize: 25,
)),
),
)
],
),
),
);
}
Here is the error,这是错误,
Class 'List<DocumentSnapshot>' has no instance method 'call'.
Receiver: Instance(length:3) of '_GrowableList'
Tried calling: call(Closure: (dynamic) => Widget)
Thank you!谢谢!
Use the map
method.使用map
方法。
Like this像这样
...
children: snapshot.data.map((data)=>_buildListItem(context,data)).toList(),
...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.