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

Shi*_*Guo 5 dart flutter

我尝试使用不同的语法来 decaring aList<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
.....
Run Code Online (Sandbox Code Playgroud)

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

非常感谢您的帮助

Gün*_*uer 3

缺少.toList()制定MappedListIterable适当的清单。如果你在 a 上调​​用.map(), .where(), 或类似的函数List,你会得到一个MappedListIterable, 并且只调用.toList()(或迭代 的其他方式MappedListIterable)才会具体化结果,因为此类操作是惰性的并且延迟到实际访问结果为止。

或者你可以改变

List<Map<String, Object>> _work;
Run Code Online (Sandbox Code Playgroud)

Iterable<Map<String, Object>> _work;
Run Code Online (Sandbox Code Playgroud)