getLocale function

String getLocale(
  1. BuildContext context, {
  2. Locale? selectedLocale,
})

Function to get the selected locale code or the locale of context as a fallback

Implementation

String getLocale(
  BuildContext context, {
  Locale? selectedLocale,
}) {
  if (selectedLocale != null) {
    return '${selectedLocale.languageCode}_${selectedLocale.countryCode}';
  }
  final Locale locale = Localizations.localeOf(context);
  return '${locale.languageCode}_${locale.countryCode}';
}