Home > database >  I have a list containes tow maps, i would to print the key and the value of map one with dart
I have a list containes tow maps, i would to print the key and the value of map one with dart

Time:04-19

void main() {
  List users = [
    {"id": 1, "name": "mike", "code": "01"},
    {"id": 2, "name": "jack", "code": "02"}
  ];
}

How do I print the id key for example or name.

CodePudding user response:

Loop the list to get access to every child Map. Then you can print any thing you want.

void main() {
  var original = [
    {"id": 1, "name": "mike", "code": "01"},
    {"id": 2, "name": "jack", "code": "02"}
  ];
  
  original.forEach((map) {
    print('id: ${map['id']}');
    print('name: ${map['name']}');
  });
}

enter image description here

  •  Tags:  
  • dart
  • Related