requireStringField function

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

Reads a required String field out of json; throws FormatException if absent or not a string.

Implementation

String requireStringField(Map<String, dynamic> json, String key) {
  final value = json[key];
  if (value == null) {
    throw FormatException('Missing required field: $key');
  }
  if (value is! String) {
    throw FormatException(
      'Field "$key" must be a String, got ${value.runtimeType}',
    );
  }
  return value;
}