getCountriesByLanguageCode static method
Future<List<Country> >
getCountriesByLanguageCode(
- List<
String> languageCode, { - CountryFilter? filter,
Search by ISO 639-1 language code: jpn
, en
, hin
, ru
,
Future<List<Country>> getCountriesByLanguageCode(){
try{
List<Country> result = await CountryProvider.getCountriesByLanguageCode(["Hin","en",]);
return result;
} catch(error) {
return null;
}
}
Implementation
static Future<List<Country>> getCountriesByLanguageCode(
List<String> languageCode,
{CountryFilter? filter}) async {
if (languageCode.isNotEmpty) {
final uri = "$_baseUrl" +
Constants.countriesByLanguageCode +
languageCode.toFormattedString! +
filter.toFormattedUri;
// print(uri);
var response = await _client.get(Uri.parse(uri));
if (response.statusCode == 200) {
var countries = List<Country>.from(jsonDecode(response.body)
.map((x) => x != null ? Country.fromJson(x) : null));
return countries;
}
throw new Exception(
"No country found. Please check if https://restcountries.eu is avialable.");
} else {
throw Exception("Language code can not be empty");
}
}