tryGetMap<A, B> method

Map<A, B>? tryGetMap<A, B>(
  1. String key, [
  2. TryGet log = TryGet.optional
])

Implementation

Map<A, B>? tryGetMap<A, B>(String key, [TryGet log = TryGet.optional]) {
  final Object? value = this[key];
  if (value is! Map) {
    log(key, <A, B>{}.runtimeType, value.runtimeType);
    return null;
  }
  try {
    // copy map to ensure type check failures here and not an access
    return Map.from(value.cast<A, B>());
  } catch (_) {
    Logs().v(
        'Unable to create "Map<$A,$B>" in event content for the key "$key" at ${StackTrace.current.firstLine}');
    return null;
  }
}