dialCodeForCountry function

String dialCodeForCountry(
  1. String countryCode
)

Returns the international dial code for the given ISO 3166-1 alpha-2 countryCode (e.g. "VN" -> "84"), or an empty string if unknown.

Locale region can also legitimately be a UN M.49 numeric area code (e.g. "419" for a generic Latin-America locale) rather than an ISO 3166-1 alpha-2 code; those cover many countries at once and have no single dial code, so they are rejected explicitly instead of relying on a coincidental map miss.

Implementation

String dialCodeForCountry(String countryCode) {
  final normalized = countryCode.toUpperCase();
  if (normalized.length != 2) return '';
  return countryDialCodes[normalized] ?? '';
}