Skip to content

Commit

Permalink
style the table better
Browse files Browse the repository at this point in the history
  • Loading branch information
Dieterbe committed May 10, 2024
1 parent 25aa08f commit d875d81
Showing 1 changed file with 63 additions and 23 deletions.
86 changes: 63 additions & 23 deletions lib/widgets/nutrition/nutritional_diary_table.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ class NutritionalDiaryTable extends StatelessWidget {
final goals = plan.nutritionalGoals;

return Table(
columnWidths: const {
0: FractionColumnWidth(0.14), // Date
1: FractionColumnWidth(0.19), // E (kcal)
2: FractionColumnWidth(0.25), // Difference
3: FractionColumnWidth(0.14), // P (g)
4: FractionColumnWidth(0.14), // C (g)
5: FractionColumnWidth(0.14), // F (g)
},
children: [
nutrionalDiaryHeader(context, goals),
...plan.logEntriesValues.entries
Expand All @@ -33,37 +41,69 @@ class NutritionalDiaryTable extends StatelessWidget {
TableRow nutrionalDiaryHeader(BuildContext context, NutritionalGoals goals) {
return TableRow(
children: [
const Text('Date'),
Text('${AppLocalizations.of(context).energyShort} (${AppLocalizations.of(context).kcal})'),
if (goals.energy != null) Text(AppLocalizations.of(context).difference),
Text('${AppLocalizations.of(context).protein} (${AppLocalizations.of(context).g})'),
Text(style: Theme.of(context).textTheme.titleMedium, 'Date'),
Text(
style: Theme.of(context).textTheme.titleMedium,
textAlign: TextAlign.end,
'${AppLocalizations.of(context).energyShort} (${AppLocalizations.of(context).kcal})'),
if (goals.energy != null)
Text(
style: Theme.of(context).textTheme.titleMedium,
textAlign: TextAlign.end,
AppLocalizations.of(context).difference),
Text(
style: Theme.of(context).textTheme.titleMedium,
textAlign: TextAlign.end,
'${AppLocalizations.of(context).proteinShort} (${AppLocalizations.of(context).g})'),
Text(
style: Theme.of(context).textTheme.titleMedium,
textAlign: TextAlign.end,
'${AppLocalizations.of(context).carbohydratesShort} (${AppLocalizations.of(context).g})'),
Text('${AppLocalizations.of(context).fatShort} (${AppLocalizations.of(context).g})'),
Text(
style: Theme.of(context).textTheme.titleMedium,
textAlign: TextAlign.end,
'${AppLocalizations.of(context).fatShort} (${AppLocalizations.of(context).g})'),
],
);
}

TableRow nutritionDiaryEntry(final BuildContext context, NutritionalGoals goals, DateTime date,
final NutritionalValues values) {
return TableRow(
children: [
GestureDetector(
onTap: () => Navigator.of(context).pushNamed(
NutritionalDiaryScreen.routeName,
arguments: NutritionalDiaryArguments(plan, date),
),
child: Text(
style:
Theme.of(context).textTheme.titleMedium?.copyWith(color: LIST_OF_COLORS3.first),
DateFormat.Md(Localizations.localeOf(context).languageCode).format(date),
)),
Text(values.energy.toStringAsFixed(0)),
if (goals.energy != null) Text((values.energy - goals.energy!).toStringAsFixed(0)),
Text(values.protein.toStringAsFixed(0)),
Text(values.carbohydrates.toStringAsFixed(0)),
Text(values.fat.toStringAsFixed(0)),
],
);
decoration: BoxDecoration(border: Border(top: BorderSide(color: Colors.grey[300]!))),
children: [
Text(
style: Theme.of(context).textTheme.titleMedium?.copyWith(color: LIST_OF_COLORS3.first),
DateFormat.Md(Localizations.localeOf(context).languageCode).format(date),
),
Text(
style: Theme.of(context).textTheme.titleMedium,
textAlign: TextAlign.end,
values.energy.toStringAsFixed(0)),
if (goals.energy != null)
Text(
style: Theme.of(context).textTheme.titleMedium,
textAlign: TextAlign.end,
(values.energy - goals.energy!).toStringAsFixed(0)),
Text(
style: Theme.of(context).textTheme.titleMedium,
textAlign: TextAlign.end,
values.protein.toStringAsFixed(0)),
Text(
style: Theme.of(context).textTheme.titleMedium,
textAlign: TextAlign.end,
values.carbohydrates.toStringAsFixed(0)),
Text(
style: Theme.of(context).textTheme.titleMedium,
textAlign: TextAlign.end,
values.fat.toStringAsFixed(0)),
].map((element) {
return GestureDetector(
onTap: () => Navigator.of(context).pushNamed(
NutritionalDiaryScreen.routeName,
arguments: NutritionalDiaryArguments(plan, date),
),
child: element);
}).toList());
}
}

0 comments on commit d875d81

Please sign in to comment.