Home > Mobile >  dart/flutter print single value from map
dart/flutter print single value from map

Time:10-19

I want to print a single value from a map.

   var myMap = {
      0: {
        key: 754, 
        name: luke, 
        time: 1665537500000}, 
      1: {
        key: 436, 
        name: obi, 
        time: 1665532400000},
    }

print(myMap[1].value("name"); // something like that

output should be: obi

CodePudding user response:

If you specify Map before "myMap", you should be able to use

print(myMap[1]["name"]);

enter image description here

CodePudding user response:

you need to achieve this way :

Map<dynamic, dynamic> myMap = {
    0: {"key": 754, "name": "luke", "time": 1665537500000},
    1: {"key": 436, "name": "obi", "time": 1665532400000},
  };

  print(myMap[1]["name"]);
}
  • Related