类型'Future <dynamic>'不是类型'List <Profile>的子类型

时间:2020-05-22 04:44:00

标签: flutter dart google-cloud-firestore

  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()
            );                  

我是新手。 当我运行代码时,出现错误:类型'Future'不是类型'List的子类型。如果更改屏幕,则会出现错误:NoSuchMethodError:方法'map'在null上调用。我该如何解决? 谢谢您的帮助。

enter image description here

1 个答案:

答案 0 :(得分:2)

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

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