getMap<K2, V2> method

Map<K2, V2> getMap<K2, V2>(
  1. K key, {
  2. Map<K2, V2> defaultValue = const {},
})

Safely gets a nested Map from the map. Example: map.getMap<String, dynamic>('user')

Implementation

Map<K2, V2> getMap<K2, V2>(K key, {Map<K2, V2> defaultValue = const {}}) {
  final value = this[key];
  if (value is Map) {
    try {
      return Map<K2, V2>.from(value);
    } catch (_) {
      return defaultValue;
    }
  }
  return defaultValue;
}