requireStringField function
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;
}