【发布时间】:2018-12-22 16:58:38
【问题描述】:
所以基本上我有这段工作代码:
List<User> users = List();
await Future.forEach(querySnapshot.documents, (doc) async {
final snapshot = await doc['user'].get();
users.add(User(id: snapshot["id"], name: snapshot["mail"]));
});
return users;
它工作正常,完全符合我的需要,但我想知道是否有办法以某种方式将其更改为地图,例如:
return querySnapshot.documents.map((doc) async {
final snapshot = await doc['user'].get();
User(id: snapshot["id"], name: snapshot["mail"]);
}).toList{growable: true};
我这样做的问题是它说:不能将 List
所以我想知道这是否可能,或者唯一的方法是使用 Future.forEach
【问题讨论】:
标签: foreach async-await dart dart-async