getCountryFromCode function

Future<Country?> getCountryFromCode(
  1. String countryCode
)

Get country from its ISO CODE

Implementation

Future<Country?> getCountryFromCode(String countryCode) async {
  final cities = await _loadCountries();

  final res = cities.where((country) {
    return country.isoCode == countryCode;
  }).toList();
  res.sort((a, b) => a.name.compareTo(b.name));

  return res.isEmpty ? null : res.first;
}