added 'proper' indicator of how many steps have been completed for a pizza event

This commit is contained in:
broodjeaap89 2021-07-27 20:58:46 +02:00
parent 1cce0767c0
commit 50371642cb
4 changed files with 32 additions and 35 deletions

View file

@ -49,6 +49,17 @@ class PizzaRecipe extends HiveObject {
); );
} }
int getStepsCompleted(){
var stepCount = 0;
for (var recipeStep in this.recipeSteps) {
if (!recipeStep.completed) {
return stepCount;
}
stepCount++;
}
return stepCount;
}
static Future<PizzaRecipe> fromYaml(yamlPath) async{ static Future<PizzaRecipe> fromYaml(yamlPath) async{
String yamlString = await loadAsset(yamlPath); String yamlString = await loadAsset(yamlPath);
var yaml = loadYaml(yamlString); var yaml = loadYaml(yamlString);

View file

@ -29,6 +29,8 @@ class RecipeStep extends HiveObject {
@HiveField(7) @HiveField(7)
List<RecipeSubStep> subSteps; List<RecipeSubStep> subSteps;
bool get completed => subSteps.every((subStep) => subStep.completed);
RecipeStep(this.name, this.description, this.waitDescription, this.waitUnit, this.waitMin, this.waitMax, this.subSteps) { RecipeStep(this.name, this.description, this.waitDescription, this.waitUnit, this.waitMin, this.waitMax, this.subSteps) {
waitValue = waitMin; waitValue = waitMin;
} }

View file

@ -11,5 +11,10 @@ class RecipeSubStep extends HiveObject {
@HiveField(1) @HiveField(1)
String description; String description;
@HiveField(2)
DateTime? completedOn;
bool get completed => completedOn != null;
RecipeSubStep(this.name, this.description); RecipeSubStep(this.name, this.description);
} }

View file

@ -28,41 +28,20 @@ class PizzaEventWidget extends StatelessWidget {
padding: const EdgeInsets.all(10), padding: const EdgeInsets.all(10),
height: 72, height: 72,
child: Row( child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween, mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[ children: <Widget>[
SizedBox( Expanded(
width: 50, child: Slider(
height: 50, min: 0.0,
child: Container( max: pizzaEvent.recipe.recipeSteps.length.toDouble(),
color: Colors.green, divisions: pizzaEvent.recipe.recipeSteps.length,
child: Container() value: pizzaEvent.recipe.getStepsCompleted().toDouble(),
) onChanged: (d) {},
), activeColor: Colors.green,
SizedBox( inactiveColor: Colors.white,
width: 50, )
height: 50, ),
child: Container( ]
color: Colors.green,
child: Container()
)
),
SizedBox(
width: 50,
height: 50,
child: Container(
color: Colors.green,
child: Container()
)
),
SizedBox(
width: 50,
height: 50,
child: Container(
color: Colors.green,
child: Container()
)
),
]
), ),
), ),
Row( Row(