fromIsoCode static method

Country? fromIsoCode(
  1. String isoCode
)

Finds a specific country by its ISO 3166-1 alpha-2 code.

The search is case-insensitive, so both 'BR' and 'br' will work.

isoCode The 2-letter ISO country code (e.g., 'BR' for Brazil, 'US' for United States).

Returns the matching Country object if found, null otherwise.

Example:

Country? usa = WorldPickerService.fromIsoCode('US');
Country? brazil = WorldPickerService.fromIsoCode('br'); // Case-insensitive

Implementation

static Country? fromIsoCode(String isoCode) {
  final countries = loadCountries();
  try {
    return countries.firstWhere(
      (country) => country.isoCode.toUpperCase() == isoCode.toUpperCase(),
    );
  } catch (e) {
    return null;
  }
}