mirror of
https://github.com/openfoodfacts/smooth-app.git
synced 2025-08-26 03:01:45 +08:00
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:
@ -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;
|
||||
|
Reference in New Issue
Block a user