filterByIngredient function
Filter by ingredient.
s
Ingredient name.
Returns List of Filter.
Implementation
Future<List<Filter>> filterByIngredient(String s) async {
try {
var response = await _getRequest("filter.php?i=${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());
}
}