From 64481bbd58e5c6ba3012309ff809c53ebcac3da3 Mon Sep 17 00:00:00 2001 From: ROG Date: Fri, 5 Jan 2024 13:16:09 -0300 Subject: [PATCH] fix: properly refresh food preferences language (#4956) * fix: properly refresh food preferences language * style: format `_changeAppLanguage` parameters --- .../user_preferences_language_selector.dart | 28 +++++++++++++++---- 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/packages/smooth_app/lib/pages/preferences/user_preferences_language_selector.dart b/packages/smooth_app/lib/pages/preferences/user_preferences_language_selector.dart index 98bb9fc9959..914918eae52 100644 --- a/packages/smooth_app/lib/pages/preferences/user_preferences_language_selector.dart +++ b/packages/smooth_app/lib/pages/preferences/user_preferences_language_selector.dart @@ -3,6 +3,7 @@ import 'package:flutter_gen/gen_l10n/app_localizations.dart'; import 'package:openfoodfacts/openfoodfacts.dart'; import 'package:provider/provider.dart'; import 'package:smooth_app/data_models/preferences/user_preferences.dart'; +import 'package:smooth_app/data_models/product_preferences.dart'; import 'package:smooth_app/generic_lib/design_constants.dart'; import 'package:smooth_app/generic_lib/widgets/language_selector.dart'; import 'package:smooth_app/pages/preferences/user_preferences_item.dart'; @@ -23,6 +24,19 @@ class UserPreferencesLanguageSelector extends StatelessWidget { ); } + Future _changeAppLanguage( + BuildContext context, + UserPreferences userPreferences, { + required OpenFoodFactsLanguage language, + }) async { + ProductQuery.setLanguage( + context, + userPreferences, + languageCode: language.code, + ); + await context.read().refresh(); + } + @override Widget build(BuildContext context) { final AppLocalizations appLocalizations = AppLocalizations.of(context); @@ -39,13 +53,15 @@ class UserPreferencesLanguageSelector extends StatelessWidget { ), child: LanguageSelector( setLanguage: (final OpenFoodFactsLanguage? language) async { - if (language != null) { - ProductQuery.setLanguage( - context, - userPreferences, - languageCode: language.code, - ); + if (language == null) { + return; } + + _changeAppLanguage( + context, + userPreferences, + language: language, + ); }, selectedLanguages: [ ProductQuery.getLanguage(),