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