getCountryByCallingCode static method
Search by calling code: 91
, 61
, 55
, 855
, 81
Future<List<Country>> getCountryByCallingCode(){
try{
List<Country> result = await CountryProvider.getCountryByCallingCode(91);
return result;
} catch(error) {
return null;
}
}
Implementation
static Future<List<Country>> getCountryByCallingCode(int callingCode,
{CountryFilter? filter}) async {
if (callingCode > 0) {
final uri = "$_baseUrl" +
Constants.countriesByCallingCode +
callingCode.toString() +
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("Calling code can not be empty");
}
}