Food: week strip shows protein / carbs / fat; over-target days in red

Each day's bar is stacked by the share of the energy from protein, carbs and
fat (as in the History chart); hovering shows the calories and grams. A day
more than 5 % over its target shows its calories in bold red. Dashboard and
app.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Bashy 2026-10-26 14:24:00 +02:00
parent c54f66c3c2
commit 2869a208f1
5 changed files with 46 additions and 11 deletions

View file

@ -122,6 +122,7 @@ class _FoodPageState extends State<FoodPage> {
Widget _week(double target) {
final mon = plus(d, -(d.weekday - 1));
final k = kcalByDay(widget.sync.store, dayIso(mon), dayIso(plus(mon, 6)));
final m = dayTotals(widget.sync.store, dayIso(mon), dayIso(plus(mon, 6)));
return Row(children: [
for (var i = 0; i < 7; i++)
() {
@ -140,12 +141,13 @@ class _FoodPageState extends State<FoodPage> {
const SizedBox(height: 3),
Container(
width: 12, height: 32, alignment: Alignment.bottomCenter,
clipBehavior: Clip.antiAlias,
decoration: BoxDecoration(color: card2, borderRadius: BorderRadius.circular(3)),
child: FractionallySizedBox(heightFactor: h / 1.15,
child: Container(decoration: BoxDecoration(color: over ? bad : good, borderRadius: BorderRadius.circular(3)))),
child: FractionallySizedBox(heightFactor: h / 1.15, child: _macroFill(m[dayIso(x)], kc)),
),
const SizedBox(height: 2),
Text(kc == null ? '' : '${kc.round()}', style: const TextStyle(fontSize: 10.5, color: muted)),
Text(kc == null ? '' : '${kc.round()}',
style: TextStyle(fontSize: 10.5, color: over ? bad : muted, fontWeight: over ? FontWeight.bold : null)),
]),
),
),
@ -154,6 +156,20 @@ class _FoodPageState extends State<FoodPage> {
]);
}
/// A week pill's fill, bottom up: protein / carbs / fat by their share of the energy, the rest grey
/// (views._macro_segs — as the History chart stacks them).
Widget _macroFill(Map<String, double>? t, double? kcal) {
if (t == null || kcal == null || kcal <= 0) return const SizedBox();
final e = {for (final k in macros) k: (t[k] ?? 0) * kcalPerG[k]!};
final total = max(kcal, e.values.fold<double>(0, (a, b) => a + b));
final rest = total - e.values.fold<double>(0, (a, b) => a + b);
return Column(children: [
if (rest / total > 0.005) Expanded(flex: (rest / total * 1000).round(), child: Container(color: muted.withValues(alpha: 0.5))),
for (final k in macros.reversed)
if (e[k]! > 0) Expanded(flex: (e[k]! / total * 1000).round(), child: Container(color: macroColors[k])),
]);
}
Widget _meal(String m, List<Entry> es) {
final t = totals(es);
// a long-pressed food can be dropped on another meal's card (db.move: only the meal changes)