Skip to content

Commit

Permalink
fix: properly refresh food preferences language (#4956)
Browse files Browse the repository at this point in the history
* fix: properly refresh food preferences language

* style: format `_changeAppLanguage` parameters
  • Loading branch information
LuanRoger authored Jan 5, 2024
1 parent 72ac084 commit 64481bb
Showing 1 changed file with 22 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -23,6 +24,19 @@ class UserPreferencesLanguageSelector extends StatelessWidget {
);
}

Future<void> _changeAppLanguage(
BuildContext context,
UserPreferences userPreferences, {
required OpenFoodFactsLanguage language,
}) async {
ProductQuery.setLanguage(
context,
userPreferences,
languageCode: language.code,
);
await context.read<ProductPreferences>().refresh();
}

@override
Widget build(BuildContext context) {
final AppLocalizations appLocalizations = AppLocalizations.of(context);
Expand All @@ -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: <OpenFoodFactsLanguage>[
ProductQuery.getLanguage(),
Expand Down

0 comments on commit 64481bb

Please sign in to comment.