getAllCountriesMap static method
Returns a map of all countries with their international dial code and area codes (if any) as the key
Example: { '+91': CountryModel(...), '+91 (11)': CountryModel(...), '+91 (22)': CountryModel(...), '+91 (33)': CountryModel(...), }
Implementation
static Map<String, CountryModel> getAllCountriesMap() {
final Map<String, CountryModel> countriesMap = {};
for (final country in rawCountries) {
final intlDialCode = country.intlDialCode;
final areaCodes = country.areaCodes;
if (areaCodes == null || areaCodes.isEmpty) {
countriesMap[intlDialCode] = country;
} else {
for (final region in areaCodes) {
countriesMap['$intlDialCode ($region)'] = country.copyWith(
currentAreaCode: region,
);
}
}
}
return countriesMap;
}