Skip to content

Commit fbbc0e8

Browse files
committed
[Cocktail] new copyWith method
1 parent 02145ff commit fbbc0e8

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

lib/util/cocktail.dart

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,28 @@ class Cocktail {
5757
shakerNeeded: apiContent.asMap["mixing"] == "YES",
5858
);
5959

60+
/// Creates a copy of this Cocktail but with the given fields replaced with the new values.
61+
Cocktail copyWith(
62+
String? name,
63+
List<CocktailIngredient>? ingredients,
64+
String? recipe,
65+
List<Image>? image,
66+
String? author,
67+
GlassType? glassType,
68+
bool? shakerNeeded,
69+
String? description,
70+
) =>
71+
Cocktail(
72+
name: name ?? this.name,
73+
ingredients: ingredients ?? this.ingredients,
74+
recipe: recipe ?? this.recipe,
75+
image: image ?? this.image,
76+
author: author ?? this.author,
77+
glassType: glassType ?? this.glassType,
78+
shakerNeeded: shakerNeeded ?? this.shakerNeeded,
79+
description: description ?? this.description,
80+
);
81+
6082
/// All the alcoholic ingredients in the cocktail.
6183
List<GenericIngredient> get alcohols => ingredients
6284
.where((element) => element.ingredient.isAlcoholic)

0 commit comments

Comments
 (0)