diff --git a/kitchenowl/lib/cubits/item_selection_cubit.dart b/kitchenowl/lib/cubits/item_selection_cubit.dart index b3eae0fe..ecc2e516 100644 --- a/kitchenowl/lib/cubits/item_selection_cubit.dart +++ b/kitchenowl/lib/cubits/item_selection_cubit.dart @@ -26,6 +26,20 @@ class ItemSelectionCubit extends Cubit { emit(state.copyWith(selectedItems: s)); } + void remove(RecipePlan recipe) { + final s = Map.of(state.selectedItems); + if (!s.containsKey(recipe)) return; + s[recipe] = {}; + emit(state.copyWith(selectedItems: s)); + } + + void add(RecipePlan recipe) { + final s = Map.of(state.selectedItems); + if (!s.containsKey(recipe)) return; + s[recipe] = Set.of(recipe.recipeWithYields.mandatoryItems); + emit(state.copyWith(selectedItems: s)); + } + List getResult() { return state.getResult(); } diff --git a/kitchenowl/lib/pages/item_selection_page.dart b/kitchenowl/lib/pages/item_selection_page.dart index 01ab9b12..e5084414 100644 --- a/kitchenowl/lib/pages/item_selection_page.dart +++ b/kitchenowl/lib/pages/item_selection_page.dart @@ -55,13 +55,21 @@ class _ItemSelectionPageState extends State { slivers: [ for (final plan in widget.plans) ...[ if (plan.recipe.items.isNotEmpty) - SliverPadding( - padding: const EdgeInsets.all(16), - sliver: SliverToBoxAdapter( - child: Text( + SliverToBoxAdapter( + child: CheckboxListTile( + title: Text( '${plan.recipe.name}${plan.yields != null ? " (${plan.yields} ${AppLocalizations.of(context)!.yields})" : ""}:', style: Theme.of(context).textTheme.headlineSmall, ), + value: state.selectedItems[plan]! + .containsAll(plan.recipeWithYields.mandatoryItems), + onChanged: (newValue) { + if (!(newValue ?? false)) { + cubit.remove(plan); + } else { + cubit.add(plan); + } + }, ), ), SliverItemGridList(