feat(meal-detail): quick-serving chips (0.5x/1x/2x + 100 g) - #1101
feat(meal-detail): quick-serving chips (0.5x/1x/2x + 100 g)#1101ibrahim-iqbal wants to merge 1 commit into
Conversation
Replaces the fixed 50-250 g quick-quantity chip row on the meal-detail sheet with chips derived from the food itself: 0.5x, 1x, 2x when the product carries a scalable serving, and a 100 g shortcut when the food is measured by mass. Foods with neither hide the row entirely instead of showing a chip that rounds to nothing meaningful. Each chip writes both the quantity and the corresponding unit through the existing onQuantityOrUnitChanged callback, so the nutriment preview recalculates through the same path a dropdown change would take. Manual entry keeps working — the callback already fires on text change. The chip data is built by quickServingOptionsFor in a new util file so the mapping is unit-testable without spinning up the sheet's widget tree, and covered by a matching test. Fixes part of simonoppowa#577
|
Thanks — this is the right shape for #577 and the helper reads cleanly. I checked it out, merged develop, and drove the real meal-detail screen: chips set the text, switch the unit, recalculate kcal, and the logged intake carries the converted amount — all correct. Two small asks before I merge: (1) meal_detail_bottom_sheet.dart:211 interpolates the visible label into the Semantics identifier, so on the uk locale the 100 g chip becomes |
Fixes part of #577 — the quick-quantity chip row on the meal-detail sheet was hard-coded to the 50/100/150/200/250 g presets, which are meaningless for foods measured by serving (a slice of pizza, a scoop of protein) and impossible to hit for liquids.
Changes
New helper —
lib/features/meal_detail/util/quick_serving_option.dartBuilds the chip row from the food itself:
scalableServingQuantity(either an explicitservingQuantityor one recovered from theservingSizestring). Selecting a chip sets the quantity + switches the unit toserving, so nutriment math goes through the same path as the existing dropdown.isSolid). Uses the localised gram-unit label passed in fromS.of(context).gramUnit.Sheet wiring —
meal_detail_bottom_sheet.dartReplaces the hard-coded chip loop with a
Builderthat consultsquickServingOptionsForand renders each option as anActionChipwrapped in aSemantics(identifier: 'meal-detail-chip-<label>')so a11y and integration tests can address individual chips. The chip'sonPressedwrites both the quantity text and the new unit through the existingonQuantityOrUnitChangedcallback, which is what the dropdown and manual typing already fan out through.Quantity is rendered with a small
_formatQuantityhelper so1.0stays1and0.5renders as0.5— the input field's regex allows both shapes but users expect the shorter one from a chip.Test —
test/unit_test/quick_serving_option_test.dartSix cases against
quickServingOptionsFor:0.5×,1×,2×,100 g)100 gchipscalableServingQuantityrecovering from a1 slice (30 g)string whenservingQuantityis nullAcceptance criteria mapping
S.of(context).gramUnit)Semantics(identifier: ...)values to each interactive chipRemembering the last-used portion stays out of scope per the issue.
Test plan
flutter test test/unit_test/quick_serving_option_test.dart— 6/6 pass locallydart formatclean on both changed files