【发布时间】:2020-09-10 08:49:59
【问题描述】:
List<Profile> demoProfiles = getdata() as List<Profile>;
Future getdata() async{
List<Profile> list=[];
list = await Firestore.instance
.collection("users").getDocuments().then((querySnapshot){
querySnapshot.documents.forEach((document) {
list.add( Profile(
photos: [document['photoUrl'],],
name: document['nickname'],
age: 2,
distance: 2,
education: document['photoUrl']
));
});
return list;
});
}
class _MainControllerState extends State<MainController> {
final MatchEngine matchEngine = MatchEngine (
matches:demoProfiles.map((Profile profile) => Match(profile: profile)).toList()
);
@override
Widget build(BuildContext context) {
return Container(
padding: EdgeInsets.fromLTRB(0.0, 60.0, 0.0, 30.0),
child: CardStack (
matchEngine: matchEngine
),
);
}
}
当我运行我的代码时,它返回错误:type 'Future' is not a subtype of type 'List' in type cast。 我该如何解决?在我从 Firebase 获取数据之前,它是 matchEngine 运行的吗? 我尝试将 await 添加到 List demoProfiles = getdata() as await List; 但它返回错误。我对颤振真的很陌生,这个问题整天都在困扰着我。请帮帮我
【问题讨论】:
-
还没有,我还在琢磨怎么做
标签: firebase flutter dart google-cloud-firestore future