Home > Net >  Display map on its own line in a text widget in Flutter
Display map on its own line in a text widget in Flutter

Time:12-02

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

CodePudding user response:

Try the following :

Column(
  children: myMap.entries
      .map(
        (e) => Text("${e.key}: ${e.value}"),
      )
      .toList(),
);

CodePudding user response:

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()}');
        },
        )
  • Related