diff --git a/lib/entities/PizzaRecipe/PizzaRecipe.dart b/lib/entities/PizzaRecipe/PizzaRecipe.dart index 94540d1..076c056 100644 --- a/lib/entities/PizzaRecipe/PizzaRecipe.dart +++ b/lib/entities/PizzaRecipe/PizzaRecipe.dart @@ -61,12 +61,6 @@ class PizzaRecipe extends HiveObject { return stepCount; } - Widget getPizzaEventRecipeWidget(BuildContext context, PizzaEventPageState pizzaEventPage) { - return ListView( - children: this.recipeSteps.map((recipeStep) => recipeStep.buildPizzaEventRecipeStepWidget(context, pizzaEventPage)).toList() - ); - } - static Future fromYaml(yamlPath) async{ String yamlString = await loadAsset(yamlPath); var yaml = loadYaml(yamlString); diff --git a/lib/entities/PizzaRecipe/RecipeStep.dart b/lib/entities/PizzaRecipe/RecipeStep.dart index 5a36ece..dc9e7a2 100644 --- a/lib/entities/PizzaRecipe/RecipeStep.dart +++ b/lib/entities/PizzaRecipe/RecipeStep.dart @@ -47,68 +47,6 @@ class RecipeStep extends HiveObject { completedOn != null; } - Widget buildPizzaEventRecipeStepWidget(BuildContext context, PizzaEventPageState pizzaEventPage){ - return this.subSteps.length > 0 ? - buildPizzaEventRecipeStepWidgetWithSubSteps(context, pizzaEventPage) : - buildPizzaEventRecipeStepWidgetWithoutSubSteps(context, pizzaEventPage); - } - - Widget buildPizzaEventRecipeStepWidgetWithSubSteps(BuildContext context, PizzaEventPageState pizzaEventPage) { - int recipeSubStepsCompleted = this.subSteps.where((subStep) => subStep.completed).length; - int recipeSubSteps = this.subSteps.length; - return ExpansionTile( - title: Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Icon(FontAwesome5.sitemap), - Text(this.name), - Text("$recipeSubStepsCompleted/$recipeSubSteps") - ], - ), - children: [ - Text(this.description), - - ] + subSteps.map((subStep) => subStep.buildTest(context, pizzaEventPage)).toList() //subStep.buildPizzaEventSubStepWidget(context, pizzaEventPage)).toList() - ); - } - - Widget buildPizzaEventRecipeStepWidgetWithoutSubSteps(BuildContext context, PizzaEventPageState pizzaEventPage) { - return ExpansionTile( - title: Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Icon(FontAwesome5.sitemap), - Text(this.name), - Text("${this.completedOn == null ? 0 : 1}/1") - ], - ), - children: [ - Text(this.description), - Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Text(this.name), - Checkbox( - value: this.completedOn != null, - onChanged: (bool? newValue) async { - if (newValue == null){ - return; - } - if (newValue){ - this.completedOn = DateTime.now(); - } else { - this.completedOn = null; - } - await pizzaEventPage.widget.pizzaEvent.save(); - pizzaEventPage.triggerSetState(); - }, - ) - ], - ) - ] - ); - } - int convertToSeconds(int value){ switch (waitUnit){ case "minutes": { diff --git a/lib/entities/PizzaRecipe/RecipeSubStep.dart b/lib/entities/PizzaRecipe/RecipeSubStep.dart index f36e3eb..75538cb 100644 --- a/lib/entities/PizzaRecipe/RecipeSubStep.dart +++ b/lib/entities/PizzaRecipe/RecipeSubStep.dart @@ -19,82 +19,4 @@ class RecipeSubStep extends HiveObject { bool get completed => completedOn != null; RecipeSubStep(this.name, this.description); - - Widget buildPizzaEventSubStepWidget(BuildContext context, PizzaEventPageState pizzaEventPage) { - return Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Text(this.name), - Checkbox( - value: this.completed, - onChanged: (bool? newValue) async { - if (newValue == null){ - return; - } - if (newValue){ - this.completedOn = DateTime.now(); - } else { - this.completedOn = null; - } - await pizzaEventPage.widget.pizzaEvent.save(); - pizzaEventPage.triggerSetState(); - }, - ) - ], - ); - } - - Widget buildTest(BuildContext context, PizzaEventPageState pizzaEventPage){ - return InkWell( - onTap: () { - showDialog( - context: context, - builder: (context) { - return getDialog(context); - } - ); - }, - child: Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Text(this.name), - Checkbox( - value: this.completed, - onChanged: (b) {}, - ) - ], - ), - ); - } - - Widget getDialog(BuildContext context){ - return Dialog( - insetPadding: EdgeInsets.all(10), - child: Container( - padding: EdgeInsets.all(10), - child: Column( - children: [ - Text(this.name), - Text(this.description), - Expanded( - child: Container() - ), - SizedBox( - width: double.infinity, - height: 70, - child: Container( - color: this.completed ? Colors.green : Colors.redAccent, - child: TextButton( - child: Text(this.completed ? "Complete" : "Todo", style: TextStyle(color: Colors.white)), - onPressed: () { - this.completedOn = this.completed ? null : DateTime.now(); - }, - ) - ) - ) - ] - ) - ) - ); - } } \ No newline at end of file diff --git a/lib/pages/PizzaEventPage.dart b/lib/pages/PizzaEventPage.dart index 55cce4d..c493311 100644 --- a/lib/pages/PizzaEventPage.dart +++ b/lib/pages/PizzaEventPage.dart @@ -1,6 +1,8 @@ import 'package:flutter/material.dart'; import 'package:fluttericon/font_awesome5_icons.dart'; import 'package:pizzaplanner/entities/PizzaEvent.dart'; +import 'package:pizzaplanner/entities/PizzaRecipe/RecipeStep.dart'; +import 'package:pizzaplanner/entities/PizzaRecipe/RecipeSubStep.dart'; class PizzaEventPage extends StatefulWidget { PizzaEvent pizzaEvent; @@ -21,10 +23,161 @@ class PizzaEventPageState extends State { resizeToAvoidBottomInset: false, body: Container( padding: EdgeInsets.all(10), - child: this.widget.pizzaEvent.recipe.getPizzaEventRecipeWidget(context, this) + child: ListView( + children: this.widget.pizzaEvent.recipe.recipeSteps.map((recipeStep) => PizzaEventRecipeStepWidget(recipeStep)).toList() + ) ) ); } triggerSetState() => setState(() {}); +} + +class PizzaEventRecipeStepWidget extends StatefulWidget { + final RecipeStep recipeStep; + + PizzaEventRecipeStepWidget(this.recipeStep); + + PizzaEventRecipeStepWidgetState createState() => PizzaEventRecipeStepWidgetState(); +} + +class PizzaEventRecipeStepWidgetState extends State { + @override + Widget build(BuildContext context) { + return this.widget.recipeStep.subSteps.length > 0 ? + buildPizzaEventRecipeStepWidgetWithSubSteps() : + buildPizzaEventRecipeStepWidgetWithoutSubSteps(); + } + + Widget buildPizzaEventRecipeStepWidgetWithSubSteps() { + int recipeSubStepsCompleted = this.widget.recipeStep.subSteps.where((subStep) => subStep.completed).length; + int recipeSubSteps = this.widget.recipeStep.subSteps.length; + return ExpansionTile( + title: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Icon(FontAwesome5.sitemap), + Text(this.widget.recipeStep.name), + Text("$recipeSubStepsCompleted/$recipeSubSteps") + ], + ), + children: [ + Text(this.widget.recipeStep.description), + + ] + this.widget.recipeStep.subSteps.map((subStep) => PizzaEventSubStepWidget(subStep)).toList() //subStep.buildPizzaEventSubStepWidget(context, pizzaEventPage)).toList() + ); + } + + Widget buildPizzaEventRecipeStepWidgetWithoutSubSteps() { + return ExpansionTile( + title: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Icon(FontAwesome5.sitemap), + Text(this.widget.recipeStep.name), + Text("${this.widget.recipeStep.completedOn == null ? 0 : 1}/1") + ], + ), + children: [ + Text(this.widget.recipeStep.description), + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Text(this.widget.recipeStep.name), + Checkbox( + value: this.widget.recipeStep.completedOn != null, + onChanged: (bool? newValue) async { + if (newValue == null){ + return; + } + this.widget.recipeStep.completedOn = newValue ? DateTime.now() : null; + setState(() {}); + }, + ) + ], + ) + ] + ); + } +} + +class PizzaEventSubStepWidget extends StatefulWidget { + final RecipeSubStep recipeSubStep; + + PizzaEventSubStepWidget(this.recipeSubStep); + + PizzaEventSubStepWidgetState createState() => PizzaEventSubStepWidgetState(); +} + +class PizzaEventSubStepWidgetState extends State { + @override + Widget build(BuildContext context){ + return InkWell( + onTap: () async { + await showDialog( + context: context, + builder: (context) { + return PizzaEventSubStepDialog(this.widget.recipeSubStep); + } + ); + setState(() {}); + }, + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Text(this.widget.recipeSubStep.name), + IgnorePointer( + child: Checkbox( + value: this.widget.recipeSubStep.completed, + onChanged: (b) {}, + ) + ) + ], + ), + ); + } +} + +class PizzaEventSubStepDialog extends StatefulWidget { + final RecipeSubStep recipeSubStep; + + PizzaEventSubStepDialog(this.recipeSubStep); + + PizzaEventSubStepDialogState createState() => PizzaEventSubStepDialogState(); +} + +class PizzaEventSubStepDialogState extends State { + @override + Widget build(BuildContext context) { + return Dialog( + insetPadding: EdgeInsets.all(10), + child: Container( + padding: EdgeInsets.all(10), + child: Column( + children: [ + Text(this.widget.recipeSubStep.name), + Text(this.widget.recipeSubStep.description), + Expanded( + child: Container() + ), + SizedBox( + width: double.infinity, + height: 70, + child: Container( + color: this.widget.recipeSubStep.completed ? Colors.green : Colors.redAccent, + child: TextButton( + child: Text(this.widget.recipeSubStep.completed ? "Complete" : "Todo", style: TextStyle(color: Colors.white)), + onPressed: () { + setState(() { + this.widget.recipeSubStep.completedOn = this.widget.recipeSubStep.completed ? null : DateTime.now(); + }); + }, + ) + ) + ) + ] + ) + ) + ); + } } \ No newline at end of file