Repository navigation
feat(nutrition): filter ingredient search by Nutri-Score - #1179
Merged
rolandgeider merged 2 commits intoApr 20, 2026
Merged
rolandgeider merged 2 commits into
rolandgeider merged 2 commits into
Conversation
Adds a "Filter by Nutri-Score" switch and an A–E discrete slider to the ingredient search filter popover. The worst acceptable grade is sent to the backend as `nutriscore__lte=<a|b|c|d|e>`, matching the new filter exposed by wger-project/wger#2295. - Extend `IngredientFilters` with `filterNutriscore` + `nutriscoreMax` - Persist both settings through `PreferenceHelper` - Expose `toggleNutriscore` and `chooseNutriscoreMax` on the riverpod notifier - Propagate `nutriscoreMax` through `NutritionPlansProvider.searchIngredient` - Add English strings `filterNutriscore` / `filterNutriscoreMax` - Widget tests cover: slider hidden until switch flipped, query emitted with/without the filter - Update stale generated Mockito overrides across the four test files that mock `NutritionPlansProvider` so the new named arg lines up Refs wger-project/wger#2295
Mirrors the React refactor in wger-project/react#1237 addressing Roland's review — the SwitchListTile + conditional Slider pair expressed one semantic decision ("what grade ceiling?") through two controls. Folded "Off" into the slider itself: - Slider stops are now Off | A | B | C | D | E (was A..E, gated by a SwitchListTile). - Off position sends no `nutriscoreMax`; A..E map as before. - Heading changed from "Filter by Nutri-Score" to "Nutri-Score filter", with a dynamic helper ("No filter" / "<grade> or better"). - Model: `IngredientFilters.nutriscoreMax` is now nullable; removed `filterNutriscore`. `copyWith` takes a `clearNutriscoreMax` flag because Dart's `??` cannot distinguish "no argument" from "null". - Storage collapsed: `saveIngredientNutriscoreMax(null)` removes the key; `getIngredientNutriscoreMax()` returns `null` when absent. - Riverpod notifier: removed `toggleNutriscore`; `chooseNutriscoreMax` now takes `NutriScore?`. - l10n: removed `filterNutriscoreMax`; added `filterNutriscoreOff`, `filterNutriscoreNoFilter`, `filterNutriscoreOrBetter` (placeholder). Tests updated: 61/61 pass.
Contributor
Author
|
Pushed b7f7e43 mirroring the React refactor in wger-project/react#1237: collapsed the Switch + Slider pair into a single Off | A | B | C | D | E slider per @rolandgeider's feedback. All 61 nutrition tests pass. |
Member
|
thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes part of wger-project/wger#2295 for the Flutter client.
Summary
Adds a "Filter by Nutri-Score" switch + A–E discrete slider to the ingredient search filter popover, mirroring the React PR (wger-project/react#1237). When enabled, the selected worst-acceptable grade is sent to the backend as
nutriscore__lte=<a|b|c|d|e>— the range lookup introduced in backend PR wger-project/wger#2305.What changed
IngredientFilters: addsfilterNutriscore(bool) +nutriscoreMax(NutriScoreenum, defaulte)PreferenceHelper: persists both settings across sessionsIngredientFiltersNotifier(riverpod):toggleNutriscore+chooseNutriscoreMaxNutritionPlansProvider.searchIngredient: forwardsnutriscoreMaxas thenutriscore__ltequery argIngredientTypeaheadfilter popover: newSwitchListTile+ 5-divisionSlider(A = 0, E = 4); slider is hidden until the switch is onfilterNutriscoreandfilterNutriscoreMaxadded toapp_en.arbtest/nutrition/ingredient_typeahead_test.dartcovering (1) slider hidden until switch flips, (2) query emitted without the filter, (3)nutriscoreMaxthreaded through when the filter is onnutritional_meal_form_test.mocks.dart,nutritional_plan_form_test.mocks.dart,settings_test.mocks.dart, andweight_screen_test.mocks.dartso existing stubs still match the extendedsearchIngredientsignatureUI
Same layout as the React PR (wger-project/react#1237 has screenshots of the equivalent UI): the existing vegan / vegetarian filter popover now has a third
SwitchListTilelabelled Filter by Nutri-Score. Flipping it reveals aSliderwith 5 discrete stops (A · B · C · D · E). The current max grade renders in the slider label. State persists across app restarts viaSharedPreferencesAsync.Test plan
flutter analyzeclean on changed filesflutter test test/nutrition/— 27 passing including the 3 new widget testsflutter test test/core/settings_test.dart test/weight/weight_screen_test.dart— mockito overrides still matchRelated