Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: properly refresh food preferences language #4956

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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