getJsonValue<T> function

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

Implementation

T getJsonValue<T>(Map<String, dynamic> json, String key) {
  if (!json.containsKey(key)) {
    throw SchemeConsistencyException('key "$key" hasn\'t found');
  } else if (json[key] is! T) {
    if ((T == double || T.toString() == 'double?') && json[key] is int) {
      return json[key].toDouble();
    } else {
      throw SchemeConsistencyException(
        'Wrong type by key "$key", expected: "$T" '
        'but has got: "${json[key].runtimeType}"',
      );
    }
  } else {
    return json[key] as T;
  }
}