decodeAnswer function
The answer's body as parsed JSON, the text when it is not JSON, or null when empty.
Implementation
Object? decodeAnswer(http.Response response) {
if (response.body.isEmpty) return null;
try {
return jsonDecode(response.body);
} on FormatException {
return response.body;
}
}