findLanguageCode static method
Determine the current language code, either from the context, or from the system-reported default locale of the device.
Implementation
static String findLanguageCode({BuildContext? context}) {
Locale? locale;
if (context != null) {
locale = Localizations.maybeLocaleOf(context);
} else {
// Get the system locale
locale = PlatformDispatcher.instance.locale;
}
final code = locale == null || locale.languageCode.isEmpty
? 'en'
: locale.languageCode;
return code;
}