localeOf static method

  1. @Deprecated('This function was found to be unhelpful.')
Locale? localeOf(
  1. BuildContext? context, {
  2. bool? allowLocaleChange,
})

Record the device's Locale at that point in time. Traditionally placed in a build() function.

Implementation

@Deprecated('This function was found to be unhelpful.')
static Locale? localeOf(BuildContext? context, {bool? allowLocaleChange}) {
  Locale? locale;
  if (context != null) {
    // May return null if unable to determine Localization.
    locale = Localizations.maybeLocaleOf(context);
  }
  if (locale != null) {
    // Assign it as the App's Locale if not assigned yet.
    _appLocale ??= locale;
    if (_deviceLocale == null) {
      _deviceLocale = locale;
    } else if (locale != _deviceLocale) {
      // The device's Locale has changed.
      _deviceLocale = locale;
      // allowLocaleChange parameter takes precedence over the field, allowDeviceChangeLocale
      final change = allowLocaleChange == null && allowDeviceChangeLocale;
      if (change || allowLocaleChange!) {
        // The App is to change Locale with this device.
        setLocale(locale);
      }
    }
  }
  return locale;
}