random function
Search a random cocktail.
Returns Random cocktail.
Implementation
Future<Cocktail> random() async {
try {
var response = await _getRequest("random.php");
if (response.length == 0) {
throw "no results found";
}
var json = jsonDecode(response);
if (json["drinks"] == null || json["drinks"].length == 0) {
throw "no results found";
}
var data = Cocktail.fromJson(json["drinks"][0]);
return data;
} catch(ex) {
throw new CocktailDBException(ex.toString());
}
}