asMap<T, K> method

Map<T, K> asMap<T, K>(
  1. String key, {
  2. Map<T, K>? def,
})

Retrieves the map of type T to K associated with the key. If the key does not exist or the value cannot be parsed as a map, returns the def value.

key The key in the map to retrieve the value from. def The default value to return if the key is not found or the value cannot be parsed. Defaults to an empty map if not provided.

Returns: The map of type T to K associated with the key or def if not found or cannot be parsed.

Implementation

Map<T, K> asMap<T, K>(String key, {Map<T, K>? def}) {
  try {
    return Map<T, K>.from(this[key]);
  } catch (e) {
    return def ?? {};
  }
}