getLocaleByCountryCode method
Searches for a given countryCode
in the list of supportedLocales, if there is a match the Locale is returned.
Oherwise orElse
is called if provided. If orElse
is not provided, default value will be the first supported locale.
Implementation
Locale getLocaleByCountryCode(String? countryCode, {Locale Function()? orElse}) {
return supportedLocales.firstWhere(
(lang) => lang.countryCode == countryCode,
orElse: orElse ?? () => supportedLocales.first,
);
}