fix: Language code usage (#3450)

* fix: Language code usage

* Update main.dart

* Fix for local != lc

* Update product_preferences.dart

* Update main.dart

* Fix tagline

* Update tagline.dart
This commit is contained in:
Marvin Möltgen
2022-12-23 10:02:14 +01:00
committed by GitHub
parent 5f824c6127
commit d6dc91d0b7
9 changed files with 53 additions and 27 deletions

View File

@ -213,6 +213,10 @@ class _SmoothAppState extends State<SmoothApp> {
final bool isOnboardingComplete =
OnboardingFlowNavigator.isOnboardingComplete(lastVisitedOnboardingPage);
themeProvider.setOnboardingComplete(isOnboardingComplete);
// Still need the value from the UserPreferences here, not the ProductQuery
// as the value is not available at this time
// will refresh each time the language changes
final String? languageCode =
context.select((UserPreferences up) => up.appLanguageCode);
@ -233,7 +237,7 @@ class _SmoothAppState extends State<SmoothApp> {
themeProvider,
),
themeMode: themeProvider.currentThemeMode,
home: SmoothAppGetLanguage(appWidget),
home: SmoothAppGetLanguage(appWidget, _userPreferences),
);
}
@ -253,23 +257,18 @@ class _SmoothAppState extends State<SmoothApp> {
/// Layer needed because we need to know the language. Language isn't available
/// in the [context] in top level widget ([SmoothApp])
class SmoothAppGetLanguage extends StatelessWidget {
const SmoothAppGetLanguage(this.appWidget);
const SmoothAppGetLanguage(this.appWidget, this.userPreferences);
final Widget appWidget;
final UserPreferences userPreferences;
@override
Widget build(BuildContext context) {
// TODO(monsieurtanuki): refactor removing the `SmoothAppGetLanguage` layer?
// will refresh each time the language changes
context.select(
(final UserPreferences userPreferences) =>
userPreferences.appLanguageCode,
);
final String languageCode = Localizations.localeOf(context).languageCode;
ProductQuery.setLanguage(languageCode);
context.read<ProductPreferences>().refresh(languageCode);
ProductQuery.setLanguage(context, userPreferences);
context.read<ProductPreferences>().refresh();
// The migration requires the language to be set in the app
// The migration requires the language to be set in the app!
_appDataImporter.startMigrationAsync();
return appWidget;