findKeyEntry<K, V> function

MapEntry<K, V?>? findKeyEntry<K, V>(
  1. Map? map,
  2. List<K>? keys, [
  3. bool ignoreCase = false
])

Finds in map a entry that has one of keys.

ignoreCase If true ignores the case of the keys.

Implementation

MapEntry<K, V?>? findKeyEntry<K, V>(Map? map, List<K>? keys,
    [bool ignoreCase = false]) {
  if (map == null || keys == null || map.isEmpty || keys.isEmpty) return null;

  if (ignoreCase) {
    for (var key in keys) {
      if (map.containsKey(key)) {
        var value = map[key] as V?;
        return MapEntry<K, V?>(key, value);
      }

      var keyLC = key.toString().toLowerCase();

      for (var k in map.keys.whereType<K>()) {
        if (k.toString().toLowerCase() == keyLC) {
          var value = map[k] as V?;
          return MapEntry<K, V?>(k, value);
        }
      }
    }
  } else {
    for (var key in keys) {
      if (map.containsKey(key)) {
        var value = map[key] as V?;
        return MapEntry<K, V?>(key, value);
      }
    }
  }

  return null;
}