findRadio method
Future<List<MyRadio> >
findRadio(
- String keyword,
- StationFilterTypes filterType, {
- bool forceHttps = false,
- SearchParameters? parameters,
- int retryAttempt = 0,
Implementation
Future<List<MyRadio>> findRadio(String keyword, StationFilterTypes filterType,
{bool forceHttps = false, SearchParameters? parameters, int retryAttempt = 0}) async {
// for language search translate keyword in english
if ((filterType == StationFilterTypes.bylanguage || filterType == StationFilterTypes.bylanguageexact) &&
languageDictionary.containsKey(keyword.toLowerCase())) keyword = languageDictionary[keyword.toLowerCase()]!;
String strUrl = "$srvUrl/stations/${filterType.name}/$keyword?${parameters?.request ?? ""}";
var url = Uri.parse(strUrl);
try {
http.Response response = await http.get(url, headers: {"User-Agent": clientName});
var ds = json.decode(utf8.decode(response.bodyBytes));
List<MyRadio> radios = [];
for (var r in ds) {
radios.add(MyRadio.build(r, forceHttps: forceHttps));
}
return radios;
} catch (e) {
retryAttempt++;
if (retryAttempt == retryLimit) rethrow;
return findRadio(keyword, filterType, forceHttps: forceHttps, parameters: parameters, retryAttempt: retryAttempt);
}
}