getMessage static method
Implementation
static Map<String, dynamic> getMessage(
Map<String, dynamic> json, bool isSSE) {
String field = isSSE ? "data" : "answer";
try {
if (json[field] != null) {
String fieldValue = json[field].toString().trim();
// Check if it's a JSON string (starts with { or [)
if (fieldValue.startsWith("{") || fieldValue.startsWith("[")) {
dynamic decoded = jsonDecode(fieldValue);
if (decoded is Map<String, dynamic>) {
return decoded;
} else {
return {"message": decoded};
}
} else {
return {"message": json[field]};
}
}
} catch (e) {
return {};
}
return {};
}