rubStackOverflow
rubStackOverflow

Reputation: 6163

How to iterate a Map<List, String>?

How to iterate a Map of Map<List, String>?
I wanna know how to list all values, and find a key: [1, 'A'].

void main() {
  print(_mapList.map);
  //??
  // _mapList.map((i, s) =>{

  // });
}

Map<List, String> _mapList = {
  [1, 'A']: "1A",
  [2, 'B']: "2A"
};

Upvotes: 2

Views: 352

Answers (2)

Ali Bayram
Ali Bayram

Reputation: 7921

There are several ways that you can do it. I will give 2 examples;

_mapList.forEach((key, value) {
  print(key);
  print(value);
});

for (var key in _mapList.keys) {
  print(key);
  print(_mapList[key]);
}

you can use map if you want to transform your map to another type;

_mapList.map((key, value) {
  print(key);
  print(value);
  return MapEntry("transformed_key", "transformed_value");
});

Upvotes: 4

CopsOnRoad
CopsOnRoad

Reputation: 267514

If you want to do it using .map, here's how you'd do:

_mapList.map((key, value) {
  print(key);
  print(value);
  return null;
});

Upvotes: 2

Related Questions