@@ -82,125 +82,53 @@ class NutritionDiaryTable extends StatelessWidget {
82
82
83
83
@override
84
84
Widget build (BuildContext context) {
85
+ final loc = AppLocalizations .of (context);
86
+
87
+ Widget columnHeader (bool left, String title) => Padding (
88
+ padding: const EdgeInsets .symmetric (vertical: tablePadding),
89
+ child: Text (
90
+ title,
91
+ style: const TextStyle (fontWeight: FontWeight .bold),
92
+ textAlign: left ? TextAlign .left : TextAlign .right,
93
+ ),
94
+ );
95
+
96
+ TableRow macroRow (int indent, bool g, String title, double Function (NutritionalValues nv) get ) {
97
+ final valFn = g ? loc.gValue : loc.kcalValue;
98
+ return TableRow (
99
+ children: [
100
+ Padding (
101
+ padding: EdgeInsets .symmetric (vertical: tablePadding, horizontal: indent * 12 ),
102
+ child: Text (title),
103
+ ),
104
+ Text (valFn (get (planned).toStringAsFixed (0 )), textAlign: TextAlign .right),
105
+ Text (valFn (get (logged).toStringAsFixed (0 )), textAlign: TextAlign .right),
106
+ Text ((get (logged) - get (planned)).toStringAsFixed (0 ), textAlign: TextAlign .right),
107
+ ],
108
+ );
109
+ }
110
+
85
111
return Table (
86
112
defaultVerticalAlignment: TableCellVerticalAlignment .middle,
87
113
border: TableBorder (
88
114
horizontalInside: BorderSide (width: 1 , color: Theme .of (context).colorScheme.outline),
89
115
),
90
116
columnWidths: const {0 : FractionColumnWidth (0.4 )},
91
117
children: [
92
- TableRow (
93
- children: [
94
- Padding (
95
- padding: const EdgeInsets .symmetric (vertical: tablePadding),
96
- child: Text (
97
- AppLocalizations .of (context).macronutrients,
98
- style: const TextStyle (fontWeight: FontWeight .bold),
99
- ),
100
- ),
101
- Text (
102
- AppLocalizations .of (context).planned,
103
- style: const TextStyle (fontWeight: FontWeight .bold),
104
- ),
105
- Text (
106
- AppLocalizations .of (context).logged,
107
- style: const TextStyle (fontWeight: FontWeight .bold),
108
- ),
109
- Text (
110
- AppLocalizations .of (context).difference,
111
- style: const TextStyle (fontWeight: FontWeight .bold),
112
- ),
113
- ],
114
- ),
115
- TableRow (
116
- children: [
117
- Padding (
118
- padding: const EdgeInsets .symmetric (vertical: tablePadding),
119
- child: Text (AppLocalizations .of (context).energy),
120
- ),
121
- Text (AppLocalizations .of (context).kcalValue (planned.energy.toStringAsFixed (0 ))),
122
- Text (AppLocalizations .of (context).kcalValue (logged.energy.toStringAsFixed (0 ))),
123
- Text ((logged.energy - planned.energy).toStringAsFixed (0 )),
124
- ],
125
- ),
126
- TableRow (
127
- children: [
128
- Padding (
129
- padding: const EdgeInsets .symmetric (vertical: tablePadding),
130
- child: Text (AppLocalizations .of (context).protein),
131
- ),
132
- Text (AppLocalizations .of (context).gValue (planned.protein.toStringAsFixed (0 ))),
133
- Text (AppLocalizations .of (context).gValue (logged.protein.toStringAsFixed (0 ))),
134
- Text ((logged.protein - planned.protein).toStringAsFixed (0 )),
135
- ],
136
- ),
137
- TableRow (
138
- children: [
139
- Padding (
140
- padding: const EdgeInsets .symmetric (vertical: tablePadding),
141
- child: Text (AppLocalizations .of (context).carbohydrates),
142
- ),
143
- Text (AppLocalizations .of (context).gValue (planned.carbohydrates.toStringAsFixed (0 ))),
144
- Text (AppLocalizations .of (context).gValue (logged.carbohydrates.toStringAsFixed (0 ))),
145
- Text ((logged.carbohydrates - planned.carbohydrates).toStringAsFixed (0 )),
146
- ],
147
- ),
148
- TableRow (
149
- children: [
150
- Padding (
151
- padding: const EdgeInsets .symmetric (vertical: tablePadding, horizontal: 12 ),
152
- child: Text (AppLocalizations .of (context).sugars),
153
- ),
154
- Text (
155
- AppLocalizations .of (context).gValue (planned.carbohydratesSugar.toStringAsFixed (0 ))),
156
- Text (AppLocalizations .of (context).gValue (logged.carbohydratesSugar.toStringAsFixed (0 ))),
157
- Text ((logged.carbohydratesSugar - planned.carbohydratesSugar).toStringAsFixed (0 )),
158
- ],
159
- ),
160
- TableRow (
161
- children: [
162
- Padding (
163
- padding: const EdgeInsets .symmetric (vertical: tablePadding),
164
- child: Text (AppLocalizations .of (context).fat),
165
- ),
166
- Text (AppLocalizations .of (context).gValue (planned.fat.toStringAsFixed (0 ))),
167
- Text (AppLocalizations .of (context).gValue (logged.fat.toStringAsFixed (0 ))),
168
- Text ((logged.fat - planned.fat).toStringAsFixed (0 )),
169
- ],
170
- ),
171
- TableRow (
172
- children: [
173
- Padding (
174
- padding: const EdgeInsets .symmetric (vertical: tablePadding, horizontal: 12 ),
175
- child: Text (AppLocalizations .of (context).saturatedFat),
176
- ),
177
- Text (AppLocalizations .of (context).gValue (planned.fatSaturated.toStringAsFixed (0 ))),
178
- Text (AppLocalizations .of (context).gValue (logged.fatSaturated.toStringAsFixed (0 ))),
179
- Text ((logged.fatSaturated - planned.fatSaturated).toStringAsFixed (0 )),
180
- ],
181
- ),
182
- TableRow (
183
- children: [
184
- Padding (
185
- padding: const EdgeInsets .symmetric (vertical: tablePadding),
186
- child: Text (AppLocalizations .of (context).fiber),
187
- ),
188
- Text (AppLocalizations .of (context).gValue (planned.fiber.toStringAsFixed (0 ))),
189
- Text (AppLocalizations .of (context).gValue (logged.fiber.toStringAsFixed (0 ))),
190
- Text ((logged.fiber - planned.fiber).toStringAsFixed (0 )),
191
- ],
192
- ),
193
- TableRow (
194
- children: [
195
- Padding (
196
- padding: const EdgeInsets .symmetric (vertical: tablePadding),
197
- child: Text (AppLocalizations .of (context).sodium),
198
- ),
199
- Text (AppLocalizations .of (context).gValue (planned.sodium.toStringAsFixed (0 ))),
200
- Text (AppLocalizations .of (context).gValue (logged.sodium.toStringAsFixed (0 ))),
201
- Text ((logged.sodium - planned.sodium).toStringAsFixed (0 )),
202
- ],
203
- ),
118
+ TableRow (children: [
119
+ columnHeader (true , loc.macronutrients),
120
+ columnHeader (false , loc.planned),
121
+ columnHeader (false , loc.logged),
122
+ columnHeader (false , loc.difference),
123
+ ]),
124
+ macroRow (0 , false , loc.energy, (NutritionalValues nv) => nv.energy),
125
+ macroRow (0 , true , loc.protein, (NutritionalValues nv) => nv.protein),
126
+ macroRow (0 , true , loc.carbohydrates, (NutritionalValues nv) => nv.carbohydrates),
127
+ macroRow (1 , true , loc.sugars, (NutritionalValues nv) => nv.carbohydratesSugar),
128
+ macroRow (0 , true , loc.fat, (NutritionalValues nv) => nv.fat),
129
+ macroRow (1 , true , loc.saturatedFat, (NutritionalValues nv) => nv.fatSaturated),
130
+ macroRow (0 , true , loc.fiber, (NutritionalValues nv) => nv.fiber),
131
+ macroRow (0 , true , loc.sodium, (NutritionalValues nv) => nv.sodium),
204
132
],
205
133
);
206
134
}
0 commit comments