getCountriesByContinent method
Search by continent: Africa
, Americas
, Asia
, Europe
, Oceania
.
Future<List<Country>> getcountryByRegionalBloc(){
try{
List<Country> result = await CountryProvider.getcountryByRegionalBloc("Asia");
return result;
} catch(error) {
return null;
}
}
Implementation
Future<List<Country>> getCountriesByContinent(String continentName, {CountryFilter? filter}) async {
if (continentName.isNotEmpty) {
final uri = "$baseUrl" + Constants.countriesByRegionalBLoc + continentName + 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("Continent name can not be empty");
}
}