【问题标题】:Why does the map method for the List class in flutter not work anymore?为什么flutter中List类的map方法不再起作用了?
【发布时间】:2021-10-09 03:47:56
【问题描述】:

有一天我打开我的项目,多个文件有错误,以前没有。所有的错误都是由于 list 类的 map 方法造成的。

错误提示:“方法 'map' 没有为类型 'List' 定义。”

如果无法让 map 方法工作,我应该如何解决这个问题?

代码片段:

    // User list from snapshot
      List<TestUser> _userListFromSnapshot(QuerySnapshot snapshot) {
        return snapshot.docs.map((doc){
          return TestUser(
            name: doc.data()['name'] ?? '', 
            year: doc.data()['year'] ?? 0,
            school: doc.data()['school'] ?? 'School',
          );
        }).toList();
      }

【问题讨论】:

    标签: list flutter methods


    【解决方案1】:

    尝试添加对象类型

     return snapshot.docs.map<TestUser>((doc){
    

    【讨论】:

    • 我尝试添加对象类型,但我仍然遇到同样的问题:(
    猜你喜欢
    • 2022-08-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-09
    • 2019-01-12
    • 2022-08-23
    • 2019-04-07
    • 1970-01-01
    相关资源
    最近更新 更多