getJsonMap<T> function Null safety

Map<String, T> getJsonMap<T>(
  1. Map<String, dynamic> json,
  2. String key
)

Implementation

Map<String, T> getJsonMap<T>(Map<String, dynamic> json, String key) {
  final Map<String, dynamic> map = getJsonValue(json, key);

  MapEntry<String, T> mapper(String key, dynamic value) {
    if (value is T) {
      return MapEntry<String, T>(key, value);
    } else {
      throw SchemeConsistencyException(
        'Wrong type by key "$key", expected: "List<$T>" '
        'but has got element in list of type: "${value.runtimeType}"',
      );
    }
  }

  return map.isEmpty ? <String, T>{} : map.map(mapper);
}