mirror of
https://github.com/kuhyx/diet-guard.git
synced 2026-11-22 15:42:19 +01:00
Found on the phone, not in the suite. Setting five meals updated the settings
preview and fired a reminder for the new 14:00 checkpoint, while the slot row
behind them kept showing the old 08/12/16/20 until the app was restarted:
onOpenSettings pushed the route without awaiting the pop, so the log screen
never rebuilt against the schedule the user had just chosen.
It now awaits and calls onScheduleMayHaveChanged, which re-reads the logged
slots and re-derives the selected slot -- the hour it pointed at may not be a
checkpoint at all any more. The other three destinations still fire and
forget, since none of them can change what this screen renders.
The regression test was confirmed to fail against the pre-fix behaviour
("Found 0 widgets with text 11:00") rather than passing vacuously.
Both files crossed the 250-line cap with the addition, so the hook moved to
log_meal_sync_mixin.dart -- which already owns refreshSlots and loggedSlots
and is the better home regardless -- and the new test into its own file.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0159b4E5hh512jYUeaJVNxfM
62 lines
2.2 KiB
Dart
62 lines
2.2 KiB
Dart
import 'package:diet_guard_app/screens/calendar_screen.dart';
|
|
import 'package:diet_guard_app/screens/food_bank_screen.dart';
|
|
import 'package:diet_guard_app/screens/history_screen.dart';
|
|
import 'package:diet_guard_app/screens/settings_screen.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:http/http.dart' as http;
|
|
|
|
/// The four app-bar destinations reachable from [LogMealScreen].
|
|
///
|
|
/// Split out of `log_meal_screen.dart` for the repo's 250-line cap. The routes
|
|
/// are unchanged -- each pushes exactly the [MaterialPageRoute] it did before.
|
|
mixin LogMealNavMixin<T extends StatefulWidget> on State<T> {
|
|
/// The screen's injected HTTP client, forwarded to [SettingsScreen].
|
|
http.Client? get syncHttpClient;
|
|
|
|
/// Re-reads the meal schedule and today's logged slots.
|
|
///
|
|
/// Called when [SettingsScreen] pops, because the schedule editor lives
|
|
/// there: without it the slot row keeps rendering the schedule that was in
|
|
/// force when this screen was built, so switching from four meals to five
|
|
/// showed the old four checkpoints until the app was restarted. Verified on
|
|
/// the phone -- the settings preview and the reminder both updated while the
|
|
/// row behind them did not.
|
|
Future<void> onScheduleMayHaveChanged();
|
|
|
|
/// Pushes the entry history screen.
|
|
void onOpenHistory() {
|
|
Navigator.of(context).push<void>(
|
|
MaterialPageRoute(builder: (_) => const HistoryScreen()),
|
|
);
|
|
}
|
|
|
|
/// Pushes the adherence calendar screen.
|
|
void onOpenCalendar() {
|
|
Navigator.of(context).push<void>(
|
|
MaterialPageRoute(builder: (_) => const CalendarScreen()),
|
|
);
|
|
}
|
|
|
|
/// Pushes the food bank screen.
|
|
void onOpenFoodBank() {
|
|
Navigator.of(context).push<void>(
|
|
MaterialPageRoute(builder: (_) => const FoodBankScreen()),
|
|
);
|
|
}
|
|
|
|
/// Pushes the settings screen, forwarding the HTTP client.
|
|
///
|
|
/// Awaits the pop, unlike the other three: settings owns the meal-schedule
|
|
/// editor, so the slot row has to be rebuilt against whatever the user
|
|
/// chose there.
|
|
Future<void> onOpenSettings() async {
|
|
await Navigator.of(context).push<void>(
|
|
MaterialPageRoute(
|
|
builder: (_) => SettingsScreen(httpClient: syncHttpClient),
|
|
),
|
|
);
|
|
if (!mounted) return;
|
|
await onScheduleMayHaveChanged();
|
|
}
|
|
}
|