changed totalTime to be a getter for preptime + cooktime

This commit is contained in:
2025-02-11 15:24:49 +01:00
parent 35df4c0cc1
commit 7fd561180e
2 changed files with 15 additions and 23 deletions

View File

@@ -2,20 +2,6 @@ import '../src/enums.dart' show Difficulty, Cuisine, MealCategory;
import 'ingredient_list_entry.dart'; import 'ingredient_list_entry.dart';
class Recipe { class Recipe {
final int id;
final String title;
final String description;
final Difficulty difficulty;
final List<IngredientListEntry> ingredients;
final List<String> steps;
final DateTime datePublished;
final Duration prepTime;
final Duration cookTime;
final Duration totalTime;
final List<String> keywords;
final MealCategory? mealCategory;
final Cuisine? cuisine;
Recipe({ Recipe({
this.id = -1, this.id = -1,
this.title = '', this.title = '',
@@ -24,7 +10,6 @@ class Recipe {
required this.datePublished, required this.datePublished,
this.prepTime = const Duration(), this.prepTime = const Duration(),
this.cookTime = const Duration(), this.cookTime = const Duration(),
this.totalTime = const Duration(),
this.mealCategory, this.mealCategory,
this.cuisine, this.cuisine,
this.ingredients = const [], this.ingredients = const [],
@@ -32,6 +17,21 @@ class Recipe {
this.steps = const [], this.steps = const [],
}); });
final Duration cookTime;
final Cuisine? cuisine;
final DateTime datePublished;
final String description;
final Difficulty difficulty;
final int id;
final List<IngredientListEntry> ingredients;
final List<String> keywords;
final MealCategory? mealCategory;
final Duration prepTime;
final List<String> steps;
final String title;
Duration get totalTime => cookTime + prepTime;
Recipe copyWith({ Recipe copyWith({
int? id, int? id,
String? title, String? title,
@@ -61,7 +61,6 @@ class Recipe {
datePublished: datePublished ?? this.datePublished, datePublished: datePublished ?? this.datePublished,
prepTime: prepTime ?? this.prepTime, prepTime: prepTime ?? this.prepTime,
cookTime: cookTime ?? this.cookTime, cookTime: cookTime ?? this.cookTime,
totalTime: totalTime ?? this.totalTime,
keywords: keywords != null keywords: keywords != null
? List<String>.from(keywords) ? List<String>.from(keywords)
: List<String>.from(this.keywords), : List<String>.from(this.keywords),

View File

@@ -66,13 +66,6 @@ class RecipeProvider extends ChangeNotifier {
} }
} }
void updateTotalTime(Duration totalTime, {bool silent = false}) {
_recipe = _recipe.copyWith(totalTime: totalTime);
if (!silent) {
notifyListeners();
}
}
void updateKeywords(List<String> keywords, {bool silent = false}) { void updateKeywords(List<String> keywords, {bool silent = false}) {
_recipe = _recipe.copyWith(keywords: keywords); _recipe = _recipe.copyWith(keywords: keywords);
if (!silent) { if (!silent) {