Skip to content

Commit

Permalink
Fix: Viewing planned meals with different portions not adjusting
Browse files Browse the repository at this point in the history
  • Loading branch information
TomBursch committed Feb 23, 2025
1 parent 1e30227 commit 49084a7
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
9 changes: 5 additions & 4 deletions kitchenowl/lib/cubits/recipe_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class RecipeCubit extends Cubit<RecipeState> {
emit(RecipeState(
recipe: recipe,
updateState: state.updateState,
selectedYields: recipe.yields,
selectedYields: state.selectedYields ?? recipe.yields,
shoppingLists: shoppingLists != null ? await shoppingLists : const [],
household: (await household) ?? state.household,
));
Expand Down Expand Up @@ -99,8 +99,9 @@ class RecipeCubit extends Cubit<RecipeState> {
recipePlan: RecipePlan(
recipe: state.recipe,
day: day,
yields: state.recipe.yields != state.selectedYields &&
state.selectedYields > 0
yields: state.selectedYields != null &&
state.recipe.yields != state.selectedYields &&
state.selectedYields! > 0
? state.selectedYields
: null,
),
Expand Down Expand Up @@ -129,7 +130,7 @@ final class RecipeState extends Equatable {
final Set<String> selectedItems;
final Recipe recipe;
final Recipe dynamicRecipe;
final int selectedYields;
final int? selectedYields;
final UpdateEnum updateState;
final List<ShoppingList> shoppingLists;
final Household? household;
Expand Down
4 changes: 2 additions & 2 deletions kitchenowl/lib/models/recipe.dart
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ class Recipe extends Model implements ISuspensionBean {
household: this.household,
);

Recipe withYields(int yields) {
if (yields == this.yields) return this;
Recipe withYields(int? yields) {
if (yields == null || yields == this.yields) return this;

return copyWith(
items: items
Expand Down
8 changes: 5 additions & 3 deletions kitchenowl/lib/pages/recipe_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ class _RecipePageState extends State<RecipePage> {
),
),
NumberSelector(
value: state.selectedYields,
value: state.selectedYields ?? state.recipe.yields,
setValue: cubit.setSelectedYields,
defaultValue: state.recipe.yields,
lowerBound: 1,
Expand Down Expand Up @@ -339,10 +339,12 @@ class _RecipePageState extends State<RecipePage> {
Expanded(
child: LoadingElevatedButton(
child: Text(
state.selectedYields != state.recipe.yields
state.selectedYields != null &&
state.selectedYields !=
state.recipe.yields
? AppLocalizations.of(context)!
.addRecipeToPlanner(
state.selectedYields,
state.selectedYields!,
)
: AppLocalizations.of(context)!
.addRecipeToPlannerShort,
Expand Down

0 comments on commit 49084a7

Please sign in to comment.