fetch<T, K> method
Makes API Request of respective function.
Implementation
Future<T> fetch<T, K>() async {
final bool _validURL = Uri.parse(_imageUrl).isAbsolute;
if (!_validURL) {
throw Exception('Invalid url requested');
}
final toURI = Uri.parse(getUrl());
final response = await client.get(toURI);
if (response.statusCode == 200) {
final Map bodyJson = jsonDecode(response.body);
if (T == AssetModel && bodyJson.containsKey('asset')) {
return AssetModel.fromJson(bodyJson['asset']) as T;
} else {
return json.decode(response.body);
}
} else {
return json.decode(response.body);
}
}