generateMessage function
origin: jogjaprov_pamor_mob_masyarakat/lib/globals.dart (generateMessage) union-of: jogjaprov_pamor_mob_responder/lib/globals.dart author: anovsiradj, opencode-go/glm-5.2 version: 2022-06-14, revised: 2026-08-17
Extract a user-readable message from a Laravel-style JSON error response.
Handles: String / List / Map with errors (String|List|Map) or message.
Implementation
String generateMessage(dynamic content) {
if (content is String) {
return content;
}
if (content is List && content.isNotEmpty) {
return content.join('\n');
}
if (content is Map) {
if (content.containsKey('errors')) {
final errors = content['errors'];
if (errors is String) {
return errors;
}
if (errors is List && errors.isNotEmpty) {
return errors.join('\n');
}
if (errors is Map && errors.values.isNotEmpty) {
return errors.values.join('\n');
}
}
if (content.containsKey('message') && content['message'] is String) {
return content['message'];
}
}
return '...';
}