0

hey I have like that List

List<String> list = ['a', 'b', 'c'];

and ı have like that map

Map<String, String> map = {'Hello': 'a', 'How': 'b', 'You': 'c'};

I want make function like that if is a i want return Hello how can i do it can you help me ?

find(a) {
 //return Hello
}
Cenk YAGMUR
  • 3,154
  • 2
  • 26
  • 42
  • I don't fully understand what you're asking, but if you want to be able to look up `Map` entries by value instead of by key, perhaps try [`Map.invert`](https://pub.dev/documentation/basics/latest/map_basics/MapBasics/invert.html) from [`package:basics`](https://pub.dev/packages/basics) or [`BiMap`](https://pub.dev/documentation/quiver/latest/quiver.collection/BiMap-class.html) from [`package:quiver`](https://pub.dev/packages/quiver). – jamesdlin Apr 18 '20 at 21:12

1 Answers1

0

I don't know if I understand you correctly.

Try this, you retrieve the key using the value

Map<String, String> map = {'Hello': 'a', 'How': 'b', 'You': 'c'};

// search for 'b' value 
var data = map.keys.firstWhere((k) => map[k] == 'b', orElse: () => null);

print(data); // prints 'How'
encubos
  • 2,915
  • 10
  • 19