How to get Map keys by values in Dart?

前端 未结 6 1509
小蘑菇
小蘑菇 2021-02-05 00:43

In Dart language how to get MAP keys by values?

I have a Map like;

{
  \"01\": \"USD\",
  \"17\": \"GBP\",
  \"33\": \"EUR\"
}

And I n

6条回答
  •  既然无缘
    2021-02-05 01:26

    If someone still need a solution, I wrote a simple library to deeply (search inside nested maps either) search by value inside Map. Usage is simple, because deepSearchByValue() is an extension method, so all you need to do is to import my library and call the method on your map:

    import 'package:deep_collection/deep_collection.dart';
    
    
    void main() {
      print({
        "01": "USD",
        "17": "GBP",
        "33": "EUR",
      }.deepSearchByValue((value) => value == 'USD'));
    }
    
    

提交回复
热议问题