Reputation: 229
For example,
Lets say I have a map:
Map<string, dynamic> myMap = {'zero': 0, 'one': 1, 'two': 2};
How can I display these values in a text widget like what is depicted below:
Map key-value pairs:
zero: 0
one: 1
two: 2
Upvotes: 0
Views: 760
Reputation: 2050
Try below code
ListView.builder(
itemCount: myMap.entries.toList().length,
itemBuilder: (cont, index) {
return Text('${myMap.entries.toList()[index].key.toString()} : ${myMap.entries.toList()[index].value.toString()}');
},
)
Upvotes: 1
Reputation: 9196
Try the following :
Column(
children: myMap.entries
.map(
(e) => Text("${e.key}: ${e.value}"),
)
.toList(),
);
Upvotes: 2