I have:
final themeMode = context.select<PreferencesChangeNotifier, ThemeMode>((notifier) => notifier.themeMode);
final locale = context.select<LocaleChangeNotifier, Locale>((notifier) => notifier.locale);
return MaterialApp.router(
locale: locale,
debugShowCheckedModeBanner: false,
scaffoldMessengerKey: MyApp.rootScaffoldMessengerKey,
localizationsDelegates: AppLocalizations.localizationsDelegates,
supportedLocales: AppLocalizations.supportedLocales,
routeInformationParser: _routeInformationParser,
routerDelegate: _routerDelegate,
title: 'MyApp',
theme: AppTheme.instance.lightTheme,
darkTheme: AppTheme.instance.darkTheme,
themeMode: themeMode,
);
But this only sets the initial Locale and even though MaterialApp gets rebuilt when locale changes, it does not reflect the change.
According to the docs, this is done using Localizations.override()
But I cannot put Localizations.override() above the MaterialApp, since localizations are not in its BuildContext.
I am completely lost where should I set the desired locale. The only thing I could think of is to override the locale on each screen, which seems hacky and I assume two sets of localizations would need to be loaded in such case.
MaterialApp maybe not rebuilding when value of locale changes.
use a
ValueListenableBuilderthat listens to changes in the locale value and then rebuilds a materialApp