changeLocale method

Future changeLocale(
  1. Locale newLocale
)

Implementation

Future changeLocale(Locale newLocale) async {
  var isInitializing = _currentLocale == null;

  var locale =
      LocaleService.findLocale(newLocale, supportedLocales) ?? fallbackLocale;

  if (_currentLocale == locale) return;

  var localizedContent =
      await LocaleService.getLocaleContent(locale, supportedLocalesMap);

  Localization.load(localizedContent);

  _currentLocale = locale;

  Intl.defaultLocale = _currentLocale?.languageCode;

  if (onLocaleChanged != null) {
    await onLocaleChanged!(locale);
  }

  if (!isInitializing && preferences != null) {
    await preferences!.savePreferredLocale(locale);
  }
}