getCountryInfo function

CountryInfo? getCountryInfo({
  1. String? countryCode,
  2. int? dialCode,
  3. String? countryName,
})

Returns a CountryInfo by countryCode, dialCode or countryName.

Implementation

CountryInfo? getCountryInfo(
    {String? countryCode, int? dialCode, String? countryName}) {
  if (countryCode != null) {
    var e = allCountriesByCode[countryCode.trim().toUpperCase()];
    if (e != null) return e;
  }

  if (dialCode != null) {
    var e = allCountriesByDialCode[dialCode];
    if (e != null) return e;
  }

  if (countryName != null) {
    var e = allCountriesByName[countryName.trim().toLowerCase()];
    if (e != null) return e;
  }

  return null;
}