0

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

3 Answers 3

1

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"]);
}
Sign up to request clarification or add additional context in comments.

Comments

1

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

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

But your question seems duplicated from here so please check online before duplicating.

Comments

0
void main() {
  var myMap = {
      0: {
        "key": 754, 
        "name": "luke", 
        "time": 1665537500000}, 
      1: {
        "key": 436, 
        "name": "obi", 
        "time": 1665532400000},
    };
  print(myMap[1]?['name']);
}

Output: enter image description here

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.