![](/img/trans.png)
[英]Class '_JsonQuerySnapshot' has no instance method '[]' flutter
[英]Class 'List<DocumentSnapshot>' has no instance method 'call' in Flutter
我想要做的是,我正在制作一個包含具有相同 uid 的所有文檔的 Future 列表,然后使用 FutureBuilder 制作一個 ListView。
給我錯誤的部分是,
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,
)),
),
)
],
),
),
);
}
這是錯誤,
Class 'List<DocumentSnapshot>' has no instance method 'call'.
Receiver: Instance(length:3) of '_GrowableList'
Tried calling: call(Closure: (dynamic) => Widget)
謝謝!
使用map
方法。
像這樣
...
children: snapshot.data.map((data)=>_buildListItem(context,data)).toList(),
...
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.