searchByLetter function
Search cocktails by first letter.
c
Cocktails letter.
Returns List of Cocktail.
Implementation
Future<List<Cocktail>> searchByLetter(String c) async {
try {
var response = await _getRequest("search.php?f=${c[0]}");
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<Cocktail> list = [];
for (var i in json["drinks"]) {
list.add(Cocktail.fromJson(i));
}
return list;
} catch(ex) {
throw new CocktailDBException(ex.toString());
}
}