changeLocale method

Future<void> changeLocale(
  1. BuildContext context,
  2. Locale newLocale
)

Changes the current locale and reloads translations.

context is the build context, used to mark the widget tree as needing a rebuild. newLocale is the new locale to set.

Implementation

Future<void> changeLocale(BuildContext context, Locale newLocale) async {
  currentLocale = newLocale;
  if (saveLocale) {
    await StorageService.setLocale(newLocale);
  }
  loadTranslations(newLocale, loader.includedTranslations);
  (context as Element).markNeedsBuild();
  logger.log("Changed locale to: ${newLocale.toLanguageTag()}",
      type: LogType.info);
}