toValueMapOf<K extends Object, V extends Object> function

Map<K, V> toValueMapOf<K extends Object, V extends Object>(
  1. Map<K, Object?> map, {
  2. bool isExposed = false,
})

Converts map to a value map of K to V, or throws if cannot convert.

The returned map cannot contain null values.

Supported types for V: String, num, int, BigInt, double, bool, DateTime, Identifier, Object.

Implementation

Map<K, V> toValueMapOf<K extends Object, V extends Object>(
  Map<K, Object?> map, {
  bool isExposed = false,
}) {
  if (map is Map<K, V>) {
    return isExposed ? Map<K, V>.unmodifiable(map) : map;
  } else {
    return map
        .map<K, V>((key, value) => MapEntry<K, V>(key, toValueOf<V>(value)));
  }
}