Files
recipe_journal/lib/models/recipe.dart
2025-02-11 16:26:50 +01:00

76 lines
2.1 KiB
Dart

import '../src/enums.dart' show Difficulty, Cuisine, MealCategory;
import 'ingredient_list_entry.dart';
class Recipe {
Recipe({
this.id = -1,
this.title = '',
this.description = '',
this.difficulty,
required this.datePublished,
this.prepTime = const Duration(),
this.cookTime = const Duration(),
this.mealCategory,
this.cuisine,
this.ingredients = const [],
this.keywords = const [],
this.steps = const [],
this.servingSize = 0,
});
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;
final int servingSize;
Duration get totalTime => cookTime + prepTime;
Recipe copyWith({
int? id,
String? title,
String? description,
Difficulty? difficulty,
List<IngredientListEntry>? ingredients,
List<String>? steps,
DateTime? datePublished,
Duration? prepTime,
Duration? cookTime,
Duration? totalTime,
List<String>? keywords,
MealCategory? mealCategory,
Cuisine? cuisine,
int? servingSize,
}) {
return Recipe(
id: id ?? this.id,
title: title ?? this.title,
description: description ?? this.description,
difficulty: difficulty ?? this.difficulty,
ingredients: ingredients != null
? List<IngredientListEntry>.from(ingredients)
: List<IngredientListEntry>.from(this.ingredients),
steps: steps != null
? List<String>.from(steps)
: List<String>.from(this.steps),
datePublished: datePublished ?? this.datePublished,
prepTime: prepTime ?? this.prepTime,
cookTime: cookTime ?? this.cookTime,
keywords: keywords != null
? List<String>.from(keywords)
: List<String>.from(this.keywords),
mealCategory: mealCategory ?? this.mealCategory,
cuisine: cuisine ?? this.cuisine,
servingSize: servingSize ?? this.servingSize,
);
}
}