fromCode static method

CountryCode? fromCode(
  1. String? code
)

Gets CountryCode based on the given country code. Returns null if not found.

Implementation

static CountryCode? fromCode(String? code) {
  if (code == null) return null;

  final allCountryCodes = codes.map(CountryCode.fromMap).toList();

  final index = allCountryCodes
      .indexWhere((c) => c.code.toUpperCase() == code.toUpperCase());
  if (index == -1) return null;

  return allCountryCodes[index];
}