Skip to content

Commit

Permalink
feat: Deselect recipes from meal plan item selection page
Browse files Browse the repository at this point in the history
  • Loading branch information
TomBursch committed Nov 20, 2024
1 parent d1cf73c commit 90b852f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
14 changes: 14 additions & 0 deletions kitchenowl/lib/cubits/item_selection_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,20 @@ class ItemSelectionCubit extends Cubit<ItemSelectionState> {
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<RecipeItem> getResult() {
return state.getResult();
}
Expand Down
16 changes: 12 additions & 4 deletions kitchenowl/lib/pages/item_selection_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,21 @@ class _ItemSelectionPageState extends State<ItemSelectionPage> {
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(
Expand Down

0 comments on commit 90b852f

Please sign in to comment.