Compare commits
4 Commits
3859700212
...
7fd561180e
| Author | SHA1 | Date | |
|---|---|---|---|
| 7fd561180e | |||
| 35df4c0cc1 | |||
| 0b58a7a794 | |||
| e8de4879eb |
@@ -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),
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
import 'package:flutter/material.dart';
|
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/ingredients_page.dart';
|
||||||
import 'create_recipe_pages/metadata_page.dart';
|
import 'create_recipe_pages/metadata_page.dart';
|
||||||
import 'create_recipe_pages/steps_page.dart';
|
import 'create_recipe_pages/steps_page.dart';
|
||||||
@@ -21,6 +23,8 @@ class _CreateRecipePageState extends State<CreateRecipePage> {
|
|||||||
const StepsPage(),
|
const StepsPage(),
|
||||||
];
|
];
|
||||||
|
|
||||||
|
late RecipeProvider _recipeProvider;
|
||||||
|
|
||||||
final List<NavigationDestination> _destinations = [
|
final List<NavigationDestination> _destinations = [
|
||||||
NavigationDestination(
|
NavigationDestination(
|
||||||
icon: Icon(Icons.list),
|
icon: Icon(Icons.list),
|
||||||
@@ -38,6 +42,7 @@ class _CreateRecipePageState extends State<CreateRecipePage> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
_recipeProvider = context.watch<RecipeProvider>();
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: AppBar(),
|
appBar: AppBar(),
|
||||||
bottomNavigationBar: NavigationBar(
|
bottomNavigationBar: NavigationBar(
|
||||||
@@ -47,7 +52,16 @@ class _CreateRecipePageState extends State<CreateRecipePage> {
|
|||||||
_currentPageIndex = value;
|
_currentPageIndex = value;
|
||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
body: _pages.elementAt(_currentPageIndex),
|
body: IndexedStack(
|
||||||
|
index: _currentPageIndex,
|
||||||
|
children: _pages,
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
super.dispose();
|
||||||
|
_recipeProvider.disposeRecipe();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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) {
|
||||||
@@ -148,4 +141,8 @@ class RecipeProvider extends ChangeNotifier {
|
|||||||
notifyListeners();
|
notifyListeners();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void disposeRecipe() {
|
||||||
|
_recipe = Recipe(datePublished: DateTime.now());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,11 +6,13 @@ class DurationPicker extends StatefulWidget {
|
|||||||
required this.onChangedCallback,
|
required this.onChangedCallback,
|
||||||
required this.width,
|
required this.width,
|
||||||
required this.height,
|
required this.height,
|
||||||
|
this.initialDuration = const Duration(),
|
||||||
});
|
});
|
||||||
|
|
||||||
final void Function(Duration duration) onChangedCallback;
|
final void Function(Duration duration) onChangedCallback;
|
||||||
final double width;
|
final double width;
|
||||||
final double height;
|
final double height;
|
||||||
|
final Duration initialDuration;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<DurationPicker> createState() => _DurationPickerState();
|
State<DurationPicker> createState() => _DurationPickerState();
|
||||||
@@ -19,6 +21,15 @@ class DurationPicker extends StatefulWidget {
|
|||||||
class _DurationPickerState extends State<DurationPicker> {
|
class _DurationPickerState extends State<DurationPicker> {
|
||||||
String _timeString = '';
|
String _timeString = '';
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
if (widget.initialDuration.inMinutes != 0) {
|
||||||
|
_timeString =
|
||||||
|
'${widget.initialDuration.inHours}${widget.initialDuration.inMinutes % 60}';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Column(
|
return Column(
|
||||||
@@ -69,7 +80,7 @@ class _DurationPickerState extends State<DurationPicker> {
|
|||||||
child: ElevatedButton(
|
child: ElevatedButton(
|
||||||
style: _buttonTheme,
|
style: _buttonTheme,
|
||||||
onPressed: () => _addTime(7),
|
onPressed: () => _addTime(7),
|
||||||
child: _getTextWidget('7'),
|
child: Text('7'),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -81,7 +92,7 @@ class _DurationPickerState extends State<DurationPicker> {
|
|||||||
child: ElevatedButton(
|
child: ElevatedButton(
|
||||||
style: _buttonTheme,
|
style: _buttonTheme,
|
||||||
onPressed: () => _addTime(8),
|
onPressed: () => _addTime(8),
|
||||||
child: _getTextWidget('8'),
|
child: Text('8'),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -93,7 +104,7 @@ class _DurationPickerState extends State<DurationPicker> {
|
|||||||
child: ElevatedButton(
|
child: ElevatedButton(
|
||||||
style: _buttonTheme,
|
style: _buttonTheme,
|
||||||
onPressed: () => _addTime(9),
|
onPressed: () => _addTime(9),
|
||||||
child: _getTextWidget('9'),
|
child: Text('9'),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -111,7 +122,7 @@ class _DurationPickerState extends State<DurationPicker> {
|
|||||||
child: ElevatedButton(
|
child: ElevatedButton(
|
||||||
style: _buttonTheme,
|
style: _buttonTheme,
|
||||||
onPressed: () => _addTime(4),
|
onPressed: () => _addTime(4),
|
||||||
child: _getTextWidget('4'),
|
child: Text('4'),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -123,7 +134,7 @@ class _DurationPickerState extends State<DurationPicker> {
|
|||||||
child: ElevatedButton(
|
child: ElevatedButton(
|
||||||
style: _buttonTheme,
|
style: _buttonTheme,
|
||||||
onPressed: () => _addTime(5),
|
onPressed: () => _addTime(5),
|
||||||
child: _getTextWidget('5'),
|
child: Text('5'),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -135,7 +146,7 @@ class _DurationPickerState extends State<DurationPicker> {
|
|||||||
child: ElevatedButton(
|
child: ElevatedButton(
|
||||||
style: _buttonTheme,
|
style: _buttonTheme,
|
||||||
onPressed: () => _addTime(6),
|
onPressed: () => _addTime(6),
|
||||||
child: _getTextWidget('6'),
|
child: Text('6'),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -153,7 +164,7 @@ class _DurationPickerState extends State<DurationPicker> {
|
|||||||
child: ElevatedButton(
|
child: ElevatedButton(
|
||||||
style: _buttonTheme,
|
style: _buttonTheme,
|
||||||
onPressed: () => _addTime(1),
|
onPressed: () => _addTime(1),
|
||||||
child: _getTextWidget('1'),
|
child: Text('1'),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -165,7 +176,7 @@ class _DurationPickerState extends State<DurationPicker> {
|
|||||||
child: ElevatedButton(
|
child: ElevatedButton(
|
||||||
style: _buttonTheme,
|
style: _buttonTheme,
|
||||||
onPressed: () => _addTime(2),
|
onPressed: () => _addTime(2),
|
||||||
child: _getTextWidget('2'),
|
child: Text('2'),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -177,7 +188,7 @@ class _DurationPickerState extends State<DurationPicker> {
|
|||||||
child: ElevatedButton(
|
child: ElevatedButton(
|
||||||
style: _buttonTheme,
|
style: _buttonTheme,
|
||||||
onPressed: () => _addTime(3),
|
onPressed: () => _addTime(3),
|
||||||
child: _getTextWidget('3'),
|
child: Text('3'),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -200,7 +211,7 @@ class _DurationPickerState extends State<DurationPicker> {
|
|||||||
child: ElevatedButton(
|
child: ElevatedButton(
|
||||||
style: _buttonTheme,
|
style: _buttonTheme,
|
||||||
onPressed: () => _addTime(0),
|
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) {
|
void _addTime(int time) {
|
||||||
if (_timeString.length >= 4) return;
|
if (_timeString.length >= 4) return;
|
||||||
if (_timeString.isEmpty && time == 0) return;
|
if (_timeString.isEmpty && time == 0) return;
|
||||||
|
|||||||
Reference in New Issue
Block a user