toList<T> method
Null safety
- dynamic creator
Converts the response to the specified type. Returns a list of the specified type.
Implementation
Future<List<T>> toList<T>(creator) {
List<T> _list = [];
return then((value) {
assert(value is Response, "Not a Response");
if (value.statusCode == 200 && value.json.runtimeType == List) {
value.json.forEach((element) {
_list.add(Activator<T>(creator).createInstance().fromJson(element));
});
return _list;
} else {
throw Exception("Response is not a list");
}
});
}