type 'Future<dynamic>' is not a subtype of type 'List<Profile>

百般思念 提交于 2020-06-01 05:50:53

问题


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

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 .


回答1:


You need to specify the return type of method fetchData

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


来源:https://stackoverflow.com/questions/61948021/type-futuredynamic-is-not-a-subtype-of-type-listprofile

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!