locale property

Locale locale

The current Locale

Implementation

static Locale get locale {
  Locale locale;
  if (_appLocale != null) {
    locale = _appLocale!;
  } else {
    final preferredLocales =
        WidgetsBinding.instance.platformDispatcher.locales;
    if (preferredLocales.isNotEmpty) {
      locale = preferredLocales.first;
      _appLocale = locale;
      _prevLocale ??= locale;
    } else {
      locale = const Locale('en', 'US');
    }
  }
  return locale;
}
void locale=(Locale? locale)

Assign a new Locale

Implementation

static set locale(Locale? locale) {
  //
  if (locale == null) {
    return;
  }
  // Has to be among the supported Locales
//    if (_localesSupported.isEmpty || _localesSupported.contains(locale)) {
  if (_appLocale == null) {
    _appLocale = locale;
    // Record the 'previous' assigned Locale
    _prevLocale ??= locale;
  } else {
    // We're changing the Locale
    if (locale != _appLocale) {
      // Important to reset to false to find any new translations.
      _localeSet = false;
      _prevLocale = _appLocale;
      _appLocale = locale;
    }
    // else, if they're the same, don't change anything.
  }
//    }
}