getISO2CodeByPrefix static method
For predefined phone number returns Country's isoCode from the dial code, Returns null if not found.
Implementation
static String? getISO2CodeByPrefix(String prefix) {
if (prefix.isNotEmpty) {
prefix = prefix.startsWith('+') ? prefix : '+$prefix';
var country = Countries.countryList
.firstWhereOrNull((country) => country['dial_code'] == prefix);
if (country != null && country['alpha_2_code'] != null) {
return country['alpha_2_code'];
}
}
return null;
}