Compare commits

...

4 Commits

4 changed files with 55 additions and 38 deletions

View File

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

View File

@@ -1,5 +1,7 @@
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import '../services/providers/recipe_provider.dart';
import 'create_recipe_pages/ingredients_page.dart';
import 'create_recipe_pages/metadata_page.dart';
import 'create_recipe_pages/steps_page.dart';
@@ -21,6 +23,8 @@ class _CreateRecipePageState extends State<CreateRecipePage> {
const StepsPage(),
];
late RecipeProvider _recipeProvider;
final List<NavigationDestination> _destinations = [
NavigationDestination(
icon: Icon(Icons.list),
@@ -38,6 +42,7 @@ class _CreateRecipePageState extends State<CreateRecipePage> {
@override
Widget build(BuildContext context) {
_recipeProvider = context.watch<RecipeProvider>();
return Scaffold(
appBar: AppBar(),
bottomNavigationBar: NavigationBar(
@@ -47,7 +52,16 @@ class _CreateRecipePageState extends State<CreateRecipePage> {
_currentPageIndex = value;
}),
),
body: _pages.elementAt(_currentPageIndex),
body: IndexedStack(
index: _currentPageIndex,
children: _pages,
),
);
}
@override
void dispose() {
super.dispose();
_recipeProvider.disposeRecipe();
}
}

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}) {
_recipe = _recipe.copyWith(keywords: keywords);
if (!silent) {
@@ -148,4 +141,8 @@ class RecipeProvider extends ChangeNotifier {
notifyListeners();
}
}
void disposeRecipe() {
_recipe = Recipe(datePublished: DateTime.now());
}
}

View File

@@ -6,11 +6,13 @@ class DurationPicker extends StatefulWidget {
required this.onChangedCallback,
required this.width,
required this.height,
this.initialDuration = const Duration(),
});
final void Function(Duration duration) onChangedCallback;
final double width;
final double height;
final Duration initialDuration;
@override
State<DurationPicker> createState() => _DurationPickerState();
@@ -19,6 +21,15 @@ class DurationPicker extends StatefulWidget {
class _DurationPickerState extends State<DurationPicker> {
String _timeString = '';
@override
void initState() {
super.initState();
if (widget.initialDuration.inMinutes != 0) {
_timeString =
'${widget.initialDuration.inHours}${widget.initialDuration.inMinutes % 60}';
}
}
@override
Widget build(BuildContext context) {
return Column(
@@ -69,7 +80,7 @@ class _DurationPickerState extends State<DurationPicker> {
child: ElevatedButton(
style: _buttonTheme,
onPressed: () => _addTime(7),
child: _getTextWidget('7'),
child: Text('7'),
),
),
),
@@ -81,7 +92,7 @@ class _DurationPickerState extends State<DurationPicker> {
child: ElevatedButton(
style: _buttonTheme,
onPressed: () => _addTime(8),
child: _getTextWidget('8'),
child: Text('8'),
),
),
),
@@ -93,7 +104,7 @@ class _DurationPickerState extends State<DurationPicker> {
child: ElevatedButton(
style: _buttonTheme,
onPressed: () => _addTime(9),
child: _getTextWidget('9'),
child: Text('9'),
),
),
),
@@ -111,7 +122,7 @@ class _DurationPickerState extends State<DurationPicker> {
child: ElevatedButton(
style: _buttonTheme,
onPressed: () => _addTime(4),
child: _getTextWidget('4'),
child: Text('4'),
),
),
),
@@ -123,7 +134,7 @@ class _DurationPickerState extends State<DurationPicker> {
child: ElevatedButton(
style: _buttonTheme,
onPressed: () => _addTime(5),
child: _getTextWidget('5'),
child: Text('5'),
),
),
),
@@ -135,7 +146,7 @@ class _DurationPickerState extends State<DurationPicker> {
child: ElevatedButton(
style: _buttonTheme,
onPressed: () => _addTime(6),
child: _getTextWidget('6'),
child: Text('6'),
),
),
),
@@ -153,7 +164,7 @@ class _DurationPickerState extends State<DurationPicker> {
child: ElevatedButton(
style: _buttonTheme,
onPressed: () => _addTime(1),
child: _getTextWidget('1'),
child: Text('1'),
),
),
),
@@ -165,7 +176,7 @@ class _DurationPickerState extends State<DurationPicker> {
child: ElevatedButton(
style: _buttonTheme,
onPressed: () => _addTime(2),
child: _getTextWidget('2'),
child: Text('2'),
),
),
),
@@ -177,7 +188,7 @@ class _DurationPickerState extends State<DurationPicker> {
child: ElevatedButton(
style: _buttonTheme,
onPressed: () => _addTime(3),
child: _getTextWidget('3'),
child: Text('3'),
),
),
),
@@ -200,7 +211,7 @@ class _DurationPickerState extends State<DurationPicker> {
child: ElevatedButton(
style: _buttonTheme,
onPressed: () => _addTime(0),
child: _getTextWidget('0'),
child: Text('0'),
),
),
),
@@ -225,10 +236,6 @@ class _DurationPickerState extends State<DurationPicker> {
);
}
Text _getTextWidget(String text) {
return Text(text);
}
void _addTime(int time) {
if (_timeString.length >= 4) return;
if (_timeString.isEmpty && time == 0) return;