filterByCategory function
Filter by Category.
s
Category name.
Returns List of Filter.
Implementation
Future<List<Filter>> filterByCategory(String s) async {
try {
var response = await _getRequest("filter.php?c=${s.trim()}");
if (response.length == 0) {
throw "no results found";
}
var json = jsonDecode(response);
if (json["drinks"] == null || json["drinks"].length == 0) {
throw "no results found";
}
List<Filter> list = [];
for (var i in json["drinks"]) {
list.add(Filter.fromJson(i));
}
return list;
} catch(ex) {
throw new CocktailDBException(ex.toString());
}
}