How can I filter a map / access the entries

Update: with control flow collection statements you can also do this:

final filteredMap = {
  for (final key in map.keys)
    if (!key.startsWith('foo')) key: map[key]
};

Original answer: Dart 2.0.0 added removeWhere which can be used to filter Map entities. Given your example, you could apply this as:

Map map;
final filteredMap = Map.from(map)..removeWhere((k, v) => !k.startsWith("foo"));

It’s not the where method you asked for, but filtering Map entities is certainly doable this way.

Leave a Comment