mirror of
https://github.com/kuhyx/diet-guard.git
synced 2026-11-20 21:52:23 +01:00
- FoodEntry.slot -> slotMinute: read via entrySlotMinute, written via slotFields (whole-hour stays byte-identical, else slot_min), kept by copyWithDeleted and the edit screen, so the phone never republishes a stripped copy of a PC entry. Out-of-range peer values echo, never throw. - Satisfaction is nearest-slot snapping (satisfiedSlots) everywhere: loggedSlotsToday, due check, kuchnia occupancy, future-day logged set (that day's schedule), slot selector. Schedule edits no longer un-log. - Future pre-log builds DateTime from slot ~/ 60, slot % 60. - Schedule history + sync go through scheduleToWire/scheduleFromWire. - Notifications: ids are slot minutes; syncToSlots cancels whatever the platform reports active (getActiveNotifications, reminder channel) that is not due, covering legacy hour ids; full 0..1439 sweep only if the lookup throws. - Settings: 15-minute dropdowns + "Custom..." (24h showTimePicker), off-grid values always selectable, counts capped by grid capacity; editor moved to widgets/meal_schedule_editor.dart + meal_time_dropdown.dart. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015npsYVB2PdtWkG7MPAi4tn
36 lines
1.3 KiB
Dart
36 lines
1.3 KiB
Dart
// The meal-schedule section: owns the schedule state and its persistence;
|
|
// the widgets themselves live in `widgets/meal_schedule_editor.dart`.
|
|
//
|
|
// Split out of `settings_screen.dart` for the repo's 250-line cap. A `part`
|
|
// mixin for the same reason as `_SettingsKcalGoal`: it drives the screen's
|
|
// private state and calls `setState`.
|
|
|
|
part of 'settings_screen.dart';
|
|
|
|
mixin _SettingsMealSchedule on State<SettingsScreen> {
|
|
MealSchedule _schedule = kDefaultSchedule;
|
|
|
|
void _loadSchedule() {
|
|
_schedule = MealScheduleService.current;
|
|
}
|
|
|
|
Future<void> _applySchedule(MealSchedule next) async {
|
|
final normalized = next.normalized();
|
|
setState(() => _schedule = normalized);
|
|
if (!MealScheduleService.isInitialized) return;
|
|
await MealScheduleService.instance.recordChange(normalized);
|
|
// The reminder ids are slot minutes, so a schedule change leaves posted
|
|
// reminders for checkpoints that no longer exist. Re-running the check
|
|
// cancels them immediately rather than leaving a stale nag until the
|
|
// next background tick.
|
|
await checkAndNotify(pullWhenDue: false);
|
|
}
|
|
|
|
List<Widget> _mealScheduleSection(BuildContext context) => [
|
|
MealScheduleEditor(
|
|
schedule: _schedule,
|
|
onChanged: (next) => unawaited(_applySchedule(next)),
|
|
),
|
|
];
|
|
}
|