Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Recipes are not scaled correctly when opened #263

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions lib/cubits/recipe_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ class RecipeCubit extends Cubit<RecipeState> {
void setSelectedYields(int selectedYields) {
emit(state.copyWith(
selectedYields: selectedYields,
dynamicRecipe: state.recipe.withYields(selectedYields),
));
}

Expand Down Expand Up @@ -87,33 +86,30 @@ class RecipeState extends Equatable {
final int selectedYields;
final UpdateEnum updateState;

const RecipeState.custom({
RecipeState.custom({
required this.recipe,
required this.selectedItems,
required this.dynamicRecipe,
this.selectedYields = 0,
this.updateState = UpdateEnum.unchanged,
});
}) : dynamicRecipe = recipe.withYields(selectedYields);

RecipeState({
required this.recipe,
this.updateState = UpdateEnum.unchanged,
int? selectedYields,
}) : dynamicRecipe = recipe,
selectedYields = selectedYields ?? recipe.yields,
}) : selectedYields = selectedYields ?? recipe.yields,
dynamicRecipe = recipe.withYields(selectedYields ?? recipe.yields),
selectedItems =
recipe.items.where((e) => !e.optional).map((e) => e.name).toList();

RecipeState copyWith({
Recipe? recipe,
Recipe? dynamicRecipe,
List<String>? selectedItems,
int? selectedYields,
UpdateEnum? updateState,
}) =>
RecipeState.custom(
recipe: recipe ?? this.recipe,
dynamicRecipe: dynamicRecipe ?? this.dynamicRecipe,
selectedItems: selectedItems ?? this.selectedItems,
selectedYields: selectedYields ?? this.selectedYields,
updateState: updateState ?? this.updateState,
Expand Down
1 change: 1 addition & 0 deletions lib/models/recipe.dart
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ class Recipe extends Model implements ISuspensionBean {
);

Recipe withYields(int yields) {
if (yields == this.yields) return this;
double factor = yields / this.yields;

return copyWith(
Expand Down