countryByCode static method

Country? countryByCode(
  1. String code
)

Implementation

static Country? countryByCode(String code) {
  if (by2code.isEmpty) {
    for (Country country in Country.values) {
      by2code[country.countryCode] = country;
    }
  }

  if (by3code.isEmpty) {
    for (Country country in Country.values) {
      by3code[country.countryCodeIso] = country;
    }
  }

  Country? info;
  try {
    if (code.length == 3) {
      info = by3code[code];
    } else if (code.length == 2) {
      info = by2code[code];
    }
  } catch (e) {
    info = null;
  }

  return info;
}