getISO2CodeByPrefix static method

String? getISO2CodeByPrefix(
  1. String prefix
)

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;
}