类型“ Future< dynamic>”不是'List< Profile>类型的子类型 [英] type 'Future<dynamic>' is not a subtype of type 'List<Profile>

查看:117
本文介绍了类型“ 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{

这篇关于类型“ Future&lt; dynamic&gt;”不是'List&lt; Profile&gt;类型的子类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆