I have a list of maps in flutter with each map having only 2 keys. I would like convert them into a single map where the first key is a key and the second key becomes the value.
This is the list of maps
List results = [[
{ key: shortcuts_cart_createCart, value: 0 },
{ key: shortcuts_cart_discountCartTotal, value: 0 },
{ key: shortcuts_selling_cart, value: 0 },
]
I would like to convert the list to this map
Map shorts = {
shortcuts_selling_cart : 0,
shortcuts_cart_createCart : 0,
shortcuts_cart_discountCartTotal : 0
}
How do I achieve that
3
Answers
you can try this
I’d use MapEntry.
Also note that your code is not syntactically valid. In Dart, you have to always quote strings, even if they are keys in a map, check the documentation.
You can use Map.fromIterable and do it by one line:
but romIterable has very weak typing. So collection-for is the only recommended way which is: