readMap<K, V> method

Map<K, V> readMap<K, V>(
  1. Map<String, Object?> obj,
  2. String field
)

Reads a Map of types K,V from field in obj.

Implementation

Map<K, V> readMap<K, V>(
  Map<String, Object?> obj,
  String field,
) {
  final value = obj[field];
  if (value is! Map ||
      !value.entries.every((entry) => entry.key is K && entry.value is V)) {
    throw DebugAdapterInvalidArgumentException(
      requestName: request,
      argumentName: field,
      expectedType: Map<K, V>,
      actualType: value.runtimeType,
      actualValue: value,
    );
  }
  return (obj[field] as Map<Object?, Object?>).cast<K, V>();
}