首页 文章

使用Dart和Flutter在类中声明Map列表

提问于
浏览
0

我尝试使用不同的语法来删除 List<Map<String, Object>> _work; 但它仍然失败并且出错

type 'MappedListIterable' is not a subtype of type 'List<Map<String, Object>> .....
MappedListIterable is from dart:_internal
List is from dart:core
Mapis is from dart:core
String is from dart:core
Object is from dart:core
.....

我想声明一个变量,它是一个Map的列表,其中键是String,值是Object . 我该怎么办?

非常感谢任何帮助

1 回答

  • 2

    缺少 .toList() 使 MappedListIterable 成为正确的列表 . 如果在 List 上调用 .map().where() 或类似函数,则会得到 MappedListIterable ,并且只调用 .toList() (或其他迭代 MappedListIterable 的方法)实现结果,因为此类操作是惰性的并且延迟到实际访问结果为止 .

    或者,您也许可以改变

    List<Map<String, Object>> _work;
    

    Iterable<Map<String, Object>> _work;
    

相关问题