skip to Main Content

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

2

Answers


  1. Try the following :

    Column(
      children: myMap.entries
          .map(
            (e) => Text("${e.key}: ${e.value}"),
          )
          .toList(),
    );
    
    Login or Signup to reply.
  2. 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()}');
            },
            )
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search