parseCountryName static method
Returns a single country if it matches the given countryName
.
Uses the application context
to determine what language is used in the
app, if provided, and checks the country names for this locale if any.
If no match is found and no locales
are given, the default language is
checked (english), followed by the rest of the available translations. If
any locales
are given, only those supported languages are used, in
addition to the context
language.
Throws an ArgumentError if no matching element is found.
Implementation
static Country parseCountryName(
String countryName, {
BuildContext? context,
List<Locale>? locales,
}) {
final String countryNameLower = countryName.toLowerCase();
final CountryLocalizations? localizations =
context != null ? CountryLocalizations.of(context) : null;
final String languageCode = _anyLocalizedNameToCode(
countryNameLower,
localizations?.locale,
locales,
);
return _getFromCode(languageCode);
}