gpt4 book ai didi

flutter - 'Future'类型不是'List 类型的子类型

转载 作者:行者123 更新时间:2023-12-03 04:22:18 26 4
gpt4 key购买 nike

  class Profile {

final List<String> photos;
final String name;
final int age;
final String education;
final String bio;
final int distance;

Profile({
this.photos,
this.name,
this.age,
this.education,
this.bio,
this.distance
});

}



class _MainControllerState extends State<MainController> {


static List<Profile> demoProfiles = fetchData();

static fetchData() async{

final db = await Firestore.instance;
List<Profile> list = [];
db.collection("users").getDocuments().then((querySnapshot){
querySnapshot.documents.forEach((document) {
list.add(Profile(
photos: document['photoUrl'],
name: document['photoUrl'],
age: document['photoUrl'],
distance: document['photoUrl'],
education: document['photoUrl']
));
});
});
return list;
}


final MatchEngine matchEngine = MatchEngine (
matches:demoProfiles.map((Profile profile) => Match(profile:
profile)).toList()
);

我是新来的 flutter 。
当我运行代码时,出现错误:类型'Future'不是类型'List的子类型。如果更改屏幕,我将收到错误消息:NoSuchMethodError:方法'map'在null上调用。我该如何解决?
感谢你们对我的帮助 。

enter image description here

最佳答案

您需要指定方法fetchData的返回类型

static Future<List<Profile>> fetchData() async{

关于flutter - 'Future<dynamic>'类型不是'List <Profile>类型的子类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61948021/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com