@@ -19,6 +19,33 @@ class MacronutrientsTable extends StatelessWidget {
19
19
Widget build (BuildContext context) {
20
20
final loc = AppLocalizations .of (context);
21
21
22
+ Widget columnHeader (String title) => Padding (
23
+ padding: const EdgeInsets .symmetric (vertical: tablePadding),
24
+ child: Text (
25
+ title,
26
+ style: const TextStyle (fontWeight: FontWeight .bold),
27
+ ),
28
+ );
29
+
30
+ TableRow macroRow (int indent, bool g, String title, double ? Function (NutritionalGoals ng) get ) {
31
+ final goal = get (nutritionalGoals);
32
+ final pct = get (plannedValuesPercentage);
33
+ final perkg = nutritionalGoalsGperKg == null ? null : get (nutritionalGoalsGperKg! );
34
+ return TableRow (
35
+ children: [
36
+ Padding (
37
+ padding: EdgeInsets .symmetric (vertical: tablePadding, horizontal: indent * 12 ),
38
+ child: Text (title),
39
+ ),
40
+ Text (goal == null
41
+ ? ''
42
+ : (g ? loc.gValue (goal.toStringAsFixed (0 )) : loc.kcalValue (goal.toStringAsFixed (0 )))),
43
+ Text (pct != null ? pct.toStringAsFixed (1 ) : '' ),
44
+ Text (perkg != null ? perkg.toStringAsFixed (1 ) : '' ),
45
+ ],
46
+ );
47
+ }
48
+
22
49
return Table (
23
50
defaultVerticalAlignment: TableCellVerticalAlignment .middle,
24
51
border: TableBorder (
@@ -31,145 +58,20 @@ class MacronutrientsTable extends StatelessWidget {
31
58
children: [
32
59
TableRow (
33
60
children: [
34
- Padding (
35
- padding: const EdgeInsets .symmetric (vertical: tablePadding),
36
- child: Text (
37
- loc.macronutrients,
38
- style: const TextStyle (fontWeight: FontWeight .bold),
39
- ),
40
- ),
41
- Text (
42
- loc.total,
43
- style: const TextStyle (fontWeight: FontWeight .bold),
44
- ),
45
- Text (
46
- loc.percentEnergy,
47
- style: const TextStyle (fontWeight: FontWeight .bold),
48
- ),
49
- Text (
50
- loc.gPerBodyKg,
51
- style: const TextStyle (fontWeight: FontWeight .bold),
52
- ),
53
- ],
54
- ),
55
- TableRow (
56
- children: [
57
- Padding (
58
- padding: const EdgeInsets .symmetric (vertical: tablePadding),
59
- child: Text (loc.energy),
60
- ),
61
- Text (
62
- nutritionalGoals.energy != null
63
- ? loc.kcalValue (nutritionalGoals.energy! .toStringAsFixed (0 ))
64
- : '' ,
65
- ),
66
- const Text ('' ),
67
- const Text ('' ),
68
- ],
69
- ),
70
- TableRow (
71
- children: [
72
- Padding (
73
- padding: const EdgeInsets .symmetric (vertical: tablePadding),
74
- child: Text (loc.protein),
75
- ),
76
- Text (nutritionalGoals.protein != null
77
- ? loc.gValue (nutritionalGoals.protein! .toStringAsFixed (0 ))
78
- : '' ),
79
- Text (plannedValuesPercentage.protein != null
80
- ? plannedValuesPercentage.protein! .toStringAsFixed (1 )
81
- : '' ),
82
- Text (nutritionalGoalsGperKg != null && nutritionalGoalsGperKg! .protein != null
83
- ? nutritionalGoalsGperKg! .protein! .toStringAsFixed (1 )
84
- : '' ),
85
- ],
86
- ),
87
- TableRow (
88
- children: [
89
- Padding (
90
- padding: const EdgeInsets .symmetric (vertical: tablePadding),
91
- child: Text (loc.carbohydrates),
92
- ),
93
- Text (nutritionalGoals.carbohydrates != null
94
- ? loc.gValue (nutritionalGoals.carbohydrates! .toStringAsFixed (0 ))
95
- : '' ),
96
- Text (plannedValuesPercentage.carbohydrates != null
97
- ? plannedValuesPercentage.carbohydrates! .toStringAsFixed (1 )
98
- : '' ),
99
- Text (nutritionalGoalsGperKg != null && nutritionalGoalsGperKg! .carbohydrates != null
100
- ? nutritionalGoalsGperKg! .carbohydrates! .toStringAsFixed (1 )
101
- : '' ),
102
- ],
103
- ),
104
- TableRow (
105
- children: [
106
- Padding (
107
- padding: const EdgeInsets .symmetric (vertical: tablePadding, horizontal: 12 ),
108
- child: Text (loc.sugars),
109
- ),
110
- const Text ('' ),
111
- const Text ('' ),
112
- Text (nutritionalGoals.carbohydratesSugar != null
113
- ? loc.gValue (nutritionalGoals.carbohydratesSugar! .toStringAsFixed (0 ))
114
- : '' ),
115
- ],
116
- ),
117
- TableRow (
118
- children: [
119
- Padding (
120
- padding: const EdgeInsets .symmetric (vertical: tablePadding),
121
- child: Text (loc.fat),
122
- ),
123
- Text (nutritionalGoals.fat != null
124
- ? loc.gValue (nutritionalGoals.fat! .toStringAsFixed (0 ))
125
- : '' ),
126
- Text (plannedValuesPercentage.fat != null
127
- ? plannedValuesPercentage.fat! .toStringAsFixed (1 )
128
- : '' ),
129
- Text (nutritionalGoalsGperKg != null && nutritionalGoalsGperKg! .fat != null
130
- ? nutritionalGoalsGperKg! .fat! .toStringAsFixed (1 )
131
- : '' ),
132
- ],
133
- ),
134
- TableRow (
135
- children: [
136
- Padding (
137
- padding: const EdgeInsets .symmetric (vertical: tablePadding, horizontal: 12 ),
138
- child: Text (loc.saturatedFat),
139
- ),
140
- const Text ('' ),
141
- const Text ('' ),
142
- Text (nutritionalGoals.fatSaturated != null
143
- ? loc.gValue (nutritionalGoals.fatSaturated! .toStringAsFixed (0 ))
144
- : '' ),
145
- ],
146
- ),
147
- TableRow (
148
- children: [
149
- Padding (
150
- padding: const EdgeInsets .symmetric (vertical: tablePadding),
151
- child: Text (loc.fiber),
152
- ),
153
- const Text ('' ),
154
- const Text ('' ),
155
- Text (nutritionalGoals.fiber != null
156
- ? loc.gValue (nutritionalGoals.fiber! .toStringAsFixed (0 ))
157
- : '' ),
158
- ],
159
- ),
160
- TableRow (
161
- children: [
162
- Padding (
163
- padding: const EdgeInsets .symmetric (vertical: tablePadding),
164
- child: Text (loc.sodium),
165
- ),
166
- const Text ('' ),
167
- const Text ('' ),
168
- Text (nutritionalGoals.sodium != null
169
- ? loc.gValue (nutritionalGoals.sodium! .toStringAsFixed (0 ))
170
- : '' ),
61
+ columnHeader (loc.macronutrients),
62
+ columnHeader (loc.total),
63
+ columnHeader (loc.percentEnergy),
64
+ columnHeader (loc.gPerBodyKg),
171
65
],
172
66
),
67
+ macroRow (0 , false , loc.energy, (NutritionalGoals ng) => ng.energy),
68
+ macroRow (0 , true , loc.protein, (NutritionalGoals ng) => ng.protein),
69
+ macroRow (0 , true , loc.carbohydrates, (NutritionalGoals ng) => ng.carbohydrates),
70
+ macroRow (1 , true , loc.sugars, (NutritionalGoals ng) => ng.carbohydratesSugar),
71
+ macroRow (0 , true , loc.fat, (NutritionalGoals ng) => ng.fat),
72
+ macroRow (1 , true , loc.saturatedFat, (NutritionalGoals ng) => ng.fatSaturated),
73
+ macroRow (0 , true , loc.fiber, (NutritionalGoals ng) => ng.fiber),
74
+ macroRow (0 , true , loc.sodium, (NutritionalGoals ng) => ng.sodium),
173
75
],
174
76
);
175
77
}
0 commit comments