to<T> method
Null safety
- dynamic creator
Converts the response to the specified type.
Implementation
Future<dynamic> to<T>(creator) {
return then((value) {
value = value as Response;
assert(value.statusCode == 200 && value.body != null, "Request failed");
if (value.json.runtimeType.toString().contains("Map")) {
return Activator<T>(creator).createInstance().fromJson(value.json);
} else {
throw Exception("The response is not a map");
}
});
}