switched to a Table for ingredient widget

This commit is contained in:
broodjeaap89 2021-07-11 11:15:44 +02:00
parent 3af6cc5bc6
commit 4ad9db0fdf
4 changed files with 28 additions and 10 deletions

View file

@ -9,11 +9,12 @@ class Ingredient {
Ingredient(this.name, this.unit, this.value); Ingredient(this.name, this.unit, this.value);
Widget getIngredientWidget(int weight){ TableRow getIngredientWidget(int pizzaCount, int doughBallSize){
return Row( return TableRow(
children: <Widget>[ children: <Widget>[
Text("${this.name.capitalize()}: "), TableCell(child: Center(child: Text("${this.name.capitalize()}"))),
Text("${this.getAbsolute(weight)}$unit") TableCell(child: Center(child: Text("${this.getAbsolute(doughBallSize)}$unit"))),
TableCell(child: Center(child: Text("${this.getAbsolute(pizzaCount * doughBallSize)}$unit"))),
], ],
); );
} }

View file

@ -7,10 +7,27 @@ class Ingredients {
Ingredients(this.ingredients, this.method); Ingredients(this.ingredients, this.method);
Widget getIngredientsWidget(int weight) { Widget getIngredientsWidget(int pizzaCount, int doughBallSize) {
return Container( return Container(
child: Column( child: Table(
children: ingredients.values.map((ingredient) => ingredient.getIngredientWidget(weight)).toList() border: TableBorder.all(),
columnWidths: const <int, TableColumnWidth>{
0: FlexColumnWidth(2),
1: FlexColumnWidth(2),
2: FlexColumnWidth(2),
},
children:
<TableRow>[
TableRow(
children: <TableCell>[
TableCell(child: Center(child: Text("Ingredient"))),
TableCell(child: Center(child: Text("Single Ball"))),
TableCell(child: Center(child: Text("Total"))),
]
)
] +
ingredients.values.map((ingredient) => ingredient.getIngredientWidget(pizzaCount, doughBallSize)).toList()
) )
); );
} }

View file

@ -16,8 +16,8 @@ class PizzaRecipe {
PizzaRecipe(this.name, this.description, this.ingredients, this.recipeSteps); PizzaRecipe(this.name, this.description, this.ingredients, this.recipeSteps);
Widget getIngredientsWidget(int weight){ Widget getIngredientsWidget(int pizzaCount, int doughBallSize){
return ingredients.getIngredientsWidget(weight); return ingredients.getIngredientsWidget(pizzaCount, doughBallSize);
} }
static Future<PizzaRecipe> fromYaml(yamlPath) async{ static Future<PizzaRecipe> fromYaml(yamlPath) async{

View file

@ -156,7 +156,7 @@ class AddPizzaEventPageState extends State<AddPizzaEventPage> {
] ]
), ),
Divider(), Divider(),
this.initialized ? this.pizzaRecipe.getIngredientsWidget(this.doughBallSize * this.pizzaCount) : Container(), this.initialized ? this.pizzaRecipe.getIngredientsWidget(this.pizzaCount, this.doughBallSize) : Container(),
Spacer(), Spacer(),
SizedBox( SizedBox(
width: double.infinity, width: double.infinity,