How can I filter a map / access the entries

前端 未结 3 899
一生所求
一生所求 2021-02-18 23:46

The Map interface doesn\'t seem to provide access to the entries as an iterable, nor does it expose a where method to filter entries. Am I missing something? Is there a simple w

3条回答
  •  情书的邮戳
    2021-02-19 00:07

    Since Dart 2.0 Maps have an entries getter that returns an Iterable> so you can do:

    MapEntry theOne = map.entries.firstWhere((entry) {
            return entry.key.startsWith('foo');
          }, orElse: () => MapEntry(null, null));
    

提交回复
热议问题