getCountriesByListOfCodes static method
Search by list of ISO 3166-1 2-letter or 3-letter country codes: ["Ind", "col", "ru"]
Future<List<Country>> getCountriesByListOfCodes(){
try{
List<Country> result = CountryProvider.getCountriesByListOfCodes(["Ind", "col", "ru"]);
return result;
} catch(error) {
return null;
}
}
Implementation
static Future<List<Country>> getCountriesByListOfCodes(List<String> codes,
{CountryFilter? filter}) async {
if (codes.isNotEmpty) {
final uri = "$_baseUrl" +
Constants.countriesByListOfCodes +
codes.toFormattedString! +
"&&" +
(filter.toFormattedUri != ""
? filter.toFormattedUri.substring(1, filter.toFormattedUri.length)
: '');
// 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("Country code can not be empty");
}
}