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

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

问题描述:

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

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

I am new to flutter. when I run my code , I got the error :type 'Future' is not a subtype of type 'List .and if I change screen I will get the error:NoSuchMethodError: The method 'map' was called on null. How can I solve it ? Thank you for helping me .

您需要指定方法 fetchData

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