mirror of
https://github.com/kuhyx/diet-guard.git
synced 2026-11-24 19:46:19 +01:00
Remove the Snack chip from the phone's slot selector
The chip was the only control that logged a meal against no slot at all (`slot: null`). Removing it leaves the row with just the four hour chips, so every logged meal now satisfies a real slot. Storage keeps its null-slot support on purpose. Entries already on disk and arriving over sync carry no `slot` key, and the `slot != null` filters in log_storage_service.loggedSlotsToday / _state.logged_slots_today are what stop them from retroactively satisfying meal slots -- so both are documented as load-bearing rather than deleted as dead code. Also corrects the MCP tool's docstring, which claimed its slot argument "may be None early in the day"; it falls back to slot_for_log, which clamps to a real hour and never returns None. Adds the widget test the chip row never had -- being untested is why the chip read as unused. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MPheLM86xUN9TGf34Ygtfz
This commit is contained in:
parent
4e3778823f
commit
372e8a19f6
@ -81,6 +81,13 @@ class FoodEntry {
|
|||||||
|
|
||||||
/// The meal-slot hour this entry satisfies (8/12/16/20), or null for a
|
/// The meal-slot hour this entry satisfies (8/12/16/20), or null for a
|
||||||
/// snack that counts toward calories but satisfies no slot.
|
/// snack that counts toward calories but satisfies no slot.
|
||||||
|
///
|
||||||
|
/// Nothing writes null any more -- the "Snack" chip was removed on
|
||||||
|
/// 2026-08-14 and every remaining writer resolves a concrete hour through
|
||||||
|
/// `slotForLog`/`slot_for_log` -- but entries already on disk and arriving
|
||||||
|
/// over sync still carry no `slot` key, so the null case and every
|
||||||
|
/// `slot != null` filter built on it are load-bearing. Dropping them would
|
||||||
|
/// make those historical entries retroactively satisfy meal slots.
|
||||||
final int? slot;
|
final int? slot;
|
||||||
|
|
||||||
/// HMAC signature, present on entries that have passed through the PC's
|
/// HMAC signature, present on entries that have passed through the PC's
|
||||||
|
|||||||
@ -7,10 +7,15 @@ import 'package:diet_guard_app/models/slot.dart';
|
|||||||
import 'package:diet_guard_app/ui/theme.dart';
|
import 'package:diet_guard_app/ui/theme.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
/// One row of [ChoiceChip]s: one per today's slot hour plus a fixed
|
/// One row of [ChoiceChip]s, one per today's slot hour. Each chip is
|
||||||
/// "Snack" chip. Each hour chip is simultaneously selectable (tap to log
|
/// simultaneously selectable (tap to log for that slot) and status-colored
|
||||||
/// for that slot) and status-colored (green+check = logged, red = due,
|
/// (green+check = logged, red = due, grey = upcoming), so no separate status
|
||||||
/// grey = upcoming), so no separate status bar or caption text is needed.
|
/// bar or caption text is needed.
|
||||||
|
///
|
||||||
|
/// There used to be a fifth "Snack" chip that selected no slot at all,
|
||||||
|
/// removed 2026-08-14. Entries with a null slot still exist in storage and
|
||||||
|
/// still arrive over sync, so the nullable types below are deliberate -- but
|
||||||
|
/// this widget no longer produces one.
|
||||||
class SlotSelectorRow extends StatelessWidget {
|
class SlotSelectorRow extends StatelessWidget {
|
||||||
/// Creates a [SlotSelectorRow].
|
/// Creates a [SlotSelectorRow].
|
||||||
const SlotSelectorRow({
|
const SlotSelectorRow({
|
||||||
@ -27,10 +32,11 @@ class SlotSelectorRow extends StatelessWidget {
|
|||||||
/// Slot hours already satisfied by today's log.
|
/// Slot hours already satisfied by today's log.
|
||||||
final Set<int> loggedSlots;
|
final Set<int> loggedSlots;
|
||||||
|
|
||||||
/// The slot currently chosen to log for, or null for "Snack".
|
/// The slot currently chosen to log for. Nullable for historical reasons
|
||||||
|
/// (see the class doc); no chip in this row selects null any more.
|
||||||
final int? selectedSlot;
|
final int? selectedSlot;
|
||||||
|
|
||||||
/// Called with the tapped slot's hour, or null for the "Snack" chip.
|
/// Called with the tapped slot's hour. Never called with null.
|
||||||
final ValueChanged<int?> onSlotSelected;
|
final ValueChanged<int?> onSlotSelected;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -43,14 +49,6 @@ class SlotSelectorRow extends StatelessWidget {
|
|||||||
final statusColors =
|
final statusColors =
|
||||||
Theme.of(context).extension<AppStatusColors>() ?? AppStatusColors.dark;
|
Theme.of(context).extension<AppStatusColors>() ?? AppStatusColors.dark;
|
||||||
final elapsed = elapsedSlots(now).toSet();
|
final elapsed = elapsedSlots(now).toSet();
|
||||||
// Snack has no logged/due/upcoming status like the hour chips, so it
|
|
||||||
// uses `accent` as its "color" instead of a status color -- but still
|
|
||||||
// needs every property below set explicitly like the hour chips are.
|
|
||||||
// Leaving any of them unset falls through to Flutter's own ChoiceChip
|
|
||||||
// default, a literal pure-white border (the one banned value in this
|
|
||||||
// system) -- the open finding the unified-design-system doc flagged.
|
|
||||||
final snackSelected = selectedSlot == null;
|
|
||||||
final snackColor = snackSelected ? scheme.primary : scheme.onSurfaceVariant;
|
|
||||||
return Wrap(
|
return Wrap(
|
||||||
spacing: AppSpacing.xs + 2,
|
spacing: AppSpacing.xs + 2,
|
||||||
runSpacing: AppSpacing.xs,
|
runSpacing: AppSpacing.xs,
|
||||||
@ -86,27 +84,6 @@ class SlotSelectorRow extends StatelessWidget {
|
|||||||
onSelected: (_) => onSlotSelected(slot),
|
onSelected: (_) => onSlotSelected(slot),
|
||||||
);
|
);
|
||||||
}),
|
}),
|
||||||
ChoiceChip(
|
|
||||||
label: const Text('Snack'),
|
|
||||||
// Icon reads lighter than the label text (rule 28): reduced
|
|
||||||
// opacity instead of the label's full-strength color.
|
|
||||||
avatar: Icon(
|
|
||||||
Icons.fastfood,
|
|
||||||
size: 14,
|
|
||||||
color: snackColor.withValues(alpha: 0.72),
|
|
||||||
),
|
|
||||||
selected: snackSelected,
|
|
||||||
backgroundColor: scheme.onSurfaceVariant.withValues(alpha: 0.15),
|
|
||||||
selectedColor: scheme.primary.withValues(alpha: 0.35),
|
|
||||||
labelStyle: TextStyle(color: snackColor),
|
|
||||||
side: BorderSide(
|
|
||||||
width: snackSelected ? 2 : 1,
|
|
||||||
color: snackSelected
|
|
||||||
? snackColor
|
|
||||||
: snackColor.withValues(alpha: 0.4),
|
|
||||||
),
|
|
||||||
onSelected: (_) => onSlotSelected(null),
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,7 +2,7 @@ name: diet_guard_app
|
|||||||
description: "Companion phone app for diet_guard: log meals on the go."
|
description: "Companion phone app for diet_guard: log meals on the go."
|
||||||
publish_to: 'none'
|
publish_to: 'none'
|
||||||
|
|
||||||
version: 1.0.8+1
|
version: 1.0.9+1
|
||||||
|
|
||||||
environment:
|
environment:
|
||||||
sdk: ^3.12.2
|
sdk: ^3.12.2
|
||||||
|
|||||||
90
app/test/widgets/slot_selector_row_test.dart
Normal file
90
app/test/widgets/slot_selector_row_test.dart
Normal file
@ -0,0 +1,90 @@
|
|||||||
|
import 'package:diet_guard_app/models/slot.dart';
|
||||||
|
import 'package:diet_guard_app/widgets/slot_selector_row.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
|
||||||
|
Future<void> _pump(
|
||||||
|
WidgetTester tester, {
|
||||||
|
required DateTime now,
|
||||||
|
Set<int> loggedSlots = const <int>{},
|
||||||
|
int? selectedSlot,
|
||||||
|
ValueChanged<int?>? onSlotSelected,
|
||||||
|
}) => tester.pumpWidget(
|
||||||
|
MaterialApp(
|
||||||
|
home: Scaffold(
|
||||||
|
body: SlotSelectorRow(
|
||||||
|
now: now,
|
||||||
|
loggedSlots: loggedSlots,
|
||||||
|
selectedSlot: selectedSlot,
|
||||||
|
onSlotSelected: onSlotSelected ?? (_) {},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
group('SlotSelectorRow', () {
|
||||||
|
testWidgets('renders exactly one chip per day slot', (tester) async {
|
||||||
|
await _pump(tester, now: DateTime(2026, 8, 14, 13));
|
||||||
|
|
||||||
|
expect(find.byType(ChoiceChip), findsNWidgets(daySlots().length));
|
||||||
|
for (final slot in daySlots()) {
|
||||||
|
expect(find.text(slotLabel(slot)), findsOneWidget);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// The "Snack" chip was removed on 2026-08-14; it was the only control
|
||||||
|
// that logged a meal against no slot at all.
|
||||||
|
testWidgets('has no Snack chip', (tester) async {
|
||||||
|
await _pump(tester, now: DateTime(2026, 8, 14, 13));
|
||||||
|
|
||||||
|
expect(find.text('Snack'), findsNothing);
|
||||||
|
expect(find.byIcon(Icons.fastfood), findsNothing);
|
||||||
|
});
|
||||||
|
|
||||||
|
testWidgets('tapping a chip reports that slot, never null', (
|
||||||
|
tester,
|
||||||
|
) async {
|
||||||
|
final selected = <int?>[];
|
||||||
|
await _pump(
|
||||||
|
tester,
|
||||||
|
now: DateTime(2026, 8, 14, 13),
|
||||||
|
onSlotSelected: selected.add,
|
||||||
|
);
|
||||||
|
|
||||||
|
for (final slot in daySlots()) {
|
||||||
|
await tester.tap(find.text(slotLabel(slot)));
|
||||||
|
}
|
||||||
|
|
||||||
|
expect(selected, daySlots());
|
||||||
|
expect(selected, isNot(contains(null)));
|
||||||
|
});
|
||||||
|
|
||||||
|
testWidgets('a logged slot gets a check avatar', (tester) async {
|
||||||
|
await _pump(
|
||||||
|
tester,
|
||||||
|
now: DateTime(2026, 8, 14, 13),
|
||||||
|
loggedSlots: {daySlots().first},
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(find.byIcon(Icons.check), findsOneWidget);
|
||||||
|
});
|
||||||
|
|
||||||
|
testWidgets('marks the selected slot', (tester) async {
|
||||||
|
final slot = daySlots().first;
|
||||||
|
await _pump(
|
||||||
|
tester,
|
||||||
|
now: DateTime(2026, 8, 14, 13),
|
||||||
|
selectedSlot: slot,
|
||||||
|
);
|
||||||
|
|
||||||
|
final chip = tester.widget<ChoiceChip>(
|
||||||
|
find.ancestor(
|
||||||
|
of: find.text(slotLabel(slot)),
|
||||||
|
matching: find.byType(ChoiceChip),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
expect(chip.selected, isTrue);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
@ -290,8 +290,9 @@ def log_meal(
|
|||||||
macros: Manually-entered nutrition (``kcal`` plus optional
|
macros: Manually-entered nutrition (``kcal`` plus optional
|
||||||
protein/carbs/fat). When given, lookups are skipped and the meal is
|
protein/carbs/fat). When given, lookups are skipped and the meal is
|
||||||
logged exactly as specified.
|
logged exactly as specified.
|
||||||
slot: The meal-slot hour to satisfy; defaults to the current elapsed
|
slot: The meal-slot hour to satisfy; when omitted (or None) it falls
|
||||||
slot (may be ``None`` early in the day, logging calories only).
|
back to ``slot_for_log``, which clamps to a real hour rather than
|
||||||
|
returning None, so the entry always satisfies some slot.
|
||||||
confirm: Set ``True`` to actually append the entry; otherwise preview.
|
confirm: Set ``True`` to actually append the entry; otherwise preview.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
|
|||||||
@ -233,6 +233,15 @@ def logged_slots_today() -> set[int]:
|
|||||||
direction. An entry without a ``slot`` field (e.g. a snack logged with no
|
direction. An entry without a ``slot`` field (e.g. a snack logged with no
|
||||||
checkpoint) contributes calories but satisfies no slot.
|
checkpoint) contributes calories but satisfies no slot.
|
||||||
|
|
||||||
|
Nothing produces a slot-less entry any more: the phone's "Snack" chip was
|
||||||
|
removed on 2026-08-14, and every remaining writer resolves a concrete hour
|
||||||
|
through ``slot_for_log`` -- the CLI (:mod:`_cli`), the gate
|
||||||
|
(:mod:`_gatelock_mealflow`) and the MCP tool (:mod:`_mcp`, which falls back
|
||||||
|
to it whenever its ``slot`` argument is omitted or None). The check below
|
||||||
|
is still load-bearing for entries already on disk and arriving over sync --
|
||||||
|
removing it would make every historical snack retroactively satisfy a meal
|
||||||
|
slot.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
The distinct integer slot hours logged today (possibly empty).
|
The distinct integer slot hours logged today (possibly empty).
|
||||||
"""
|
"""
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user