Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Declare a List of Map in a class with Dart and Flutter

Tags:

flutter

dart

I tried delcaring a List<Map<String, Object>> _work; with different syntax but it still failed and gave an error

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
.....

I want to declare a variable which is a list of Map with key being String and value being Object. How should I do it?

Many thanks for any helps

like image 543
Shiro Guo Avatar asked Oct 16 '22 21:10

Shiro Guo


1 Answers

There is a .toList() missing to make the MappedListIterable a proper list. If you call .map(), .where(), or similar functions on a List, you get a MappedListIterable, and only calling .toList() (or other ways that iterate the MappedListIterable) materialize the result, because such operations are lazy and delayed until the result is actually accessed.

Alternatively you might be able to change

List<Map<String, Object>> _work;

to

Iterable<Map<String, Object>> _work;
like image 194
Günter Zöchbauer Avatar answered Oct 20 '22 23:10

Günter Zöchbauer