Date picker to app bar, no cover by keyboard
Some checks are pending
dependency freshness / dependencies on newest stable (push) Waiting to run
file-length / file length <= 250 lines (push) Waiting to run
md-naming / markdown naming convention (push) Waiting to run
pre-commit / pre-commit (${{ matrix.group }}) (mypy, mypy, ) (push) Waiting to run
pre-commit / pre-commit (${{ matrix.group }}) (pylint, pylint, ) (push) Waiting to run
pre-commit / pre-commit (${{ matrix.group }}) (rest, , mypy,pylint) (push) Waiting to run
Tests / test (push) Waiting to run
release-apk / release (APK) (push) Waiting to run
repo-contract / repo contract (push) Waiting to run

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WzxdWWy9HCAx2bNSRPvmTW
This commit is contained in:
Krzysztof Rudnicki 2026-11-17 22:36:07 +01:00
parent 0c76dfd839
commit eec847bb6c
8 changed files with 243 additions and 53 deletions

View File

@ -31,7 +31,8 @@ Nutrition nutritionFromControllers(MacroControllers macros, String source) =>
source: source, source: source,
); );
/// The five destination buttons in [LogMealScreen]'s app bar. /// The destination buttons in [LogMealScreen]'s app bar, after [leading]
/// (the date picker).
/// ///
/// Split out of `log_meal_screen.dart` for the repo's 250-line cap. Returned /// Split out of `log_meal_screen.dart` for the repo's 250-line cap. Returned
/// as a list to be spread into `AppBar.actions`, so the bar's structure and /// as a list to be spread into `AppBar.actions`, so the bar's structure and
@ -42,7 +43,9 @@ List<Widget> logMealAppBarActions({
required VoidCallback onCalendar, required VoidCallback onCalendar,
required VoidCallback onSettings, required VoidCallback onSettings,
required VoidCallback onBody, required VoidCallback onBody,
List<Widget> leading = const [],
}) => [ }) => [
...leading,
IconButton( IconButton(
icon: const Icon(Icons.monitor_weight, semanticLabel: 'Body'), icon: const Icon(Icons.monitor_weight, semanticLabel: 'Body'),
onPressed: onBody, onPressed: onBody,

View File

@ -12,7 +12,6 @@ import 'package:diet_guard_app/models/meal_schedule.dart';
import 'package:diet_guard_app/models/slot.dart'; import 'package:diet_guard_app/models/slot.dart';
import 'package:diet_guard_app/services/log_storage_service.dart'; import 'package:diet_guard_app/services/log_storage_service.dart';
import 'package:diet_guard_app/services/meal_schedule_service.dart'; import 'package:diet_guard_app/services/meal_schedule_service.dart';
import 'package:diet_guard_app/ui/theme.dart';
import 'package:diet_guard_app/widgets/pickers/pickers.dart'; import 'package:diet_guard_app/widgets/pickers/pickers.dart';
import 'package:diet_guard_app/widgets/slot_selector_row.dart'; import 'package:diet_guard_app/widgets/slot_selector_row.dart';
import 'package:material_ui/material_ui.dart'; import 'package:material_ui/material_ui.dart';
@ -82,45 +81,48 @@ mixin LogMealFutureMixin<T extends StatefulWidget> on State<T> {
onLogDateChanged(); onLogDateChanged();
} }
/// The "When" row: a "Log for later" button, or the picked date with a /// The app bar's date actions: the picker (leftmost icon) and, once a date
/// button to change it and one to clear back to today. /// is picked, a way back to today. A picked date tints the picker gold with
Widget buildWhenRow(BuildContext context) { /// a small dot; no text is painted.
List<Widget> buildDateActions(BuildContext context) {
final date = _futureDate; final date = _futureDate;
final scheme = Theme.of(context).colorScheme; final gold = Theme.of(context).colorScheme.primary;
return Row( return [
children: [ IconButton(
// Today is the default and shows nothing; only a picked date (data) // Not Icons.calendar_month: the bar's own "Calendar" nav button uses
// is shown, marked by the calendar glyph. // that, and two on screen make `find.byIcon` ambiguous.
if (date != null) ...[ icon: Stack(
Icon( clipBehavior: Clip.none,
Icons.event, children: [
size: 18, Icon(
color: scheme.onSurfaceVariant, Icons.edit_calendar,
semanticLabel: 'Log date', color: date == null ? null : gold,
), semanticLabel: date == null ? 'Log for later' : 'Change date',
const SizedBox(width: AppSpacing.xs), ),
], if (date != null)
Expanded( Positioned(
child: date == null ? const SizedBox() : Text(localDateKey(date)), top: -1,
right: -1,
child: Container(
key: const ValueKey('log-date-badge'),
width: 8,
height: 8,
decoration: BoxDecoration(
color: gold,
shape: BoxShape.circle,
),
),
),
],
), ),
onPressed: _pickFutureDate,
),
if (date != null)
IconButton( IconButton(
// Not Icons.calendar_month: the app bar's own "Calendar" nav button icon: const Icon(Icons.close, semanticLabel: 'Back to today'),
// already uses that, and a second one on screen makes onPressed: resetFutureLog,
// `find.byIcon` ambiguous for widget tests (and taps) alike.
icon: Icon(
Icons.date_range,
size: 18,
semanticLabel: date == null ? 'Log for later' : 'Change date',
),
onPressed: _pickFutureDate,
), ),
if (date != null) ];
IconButton(
icon: const Icon(Icons.close, semanticLabel: 'Back to today'),
onPressed: resetFutureLog,
),
],
);
} }
/// The slot row for a picked future date, else nothing. /// The slot row for a picked future date, else nothing.

View File

@ -168,6 +168,8 @@ class _LogMealScreenState extends State<LogMealScreen>
final due = dueMode; final due = dueMode;
// Dimmed while Claude works, but never moved: nothing is added around it. // Dimmed while Claude works, but never moved: nothing is added around it.
final busy = claudeState == ClaudeButtonState.sending; final busy = claudeState == ClaudeButtonState.sending;
// Hard rule: nothing sits under the keyboard, so the extras collapse.
final typing = MediaQuery.viewInsetsOf(context).bottom > 0;
final dim = busy || claudeState == ClaudeButtonState.queued; final dim = busy || claudeState == ClaudeButtonState.queued;
return Scaffold( return Scaffold(
appBar: due appBar: due
@ -179,6 +181,7 @@ class _LogMealScreenState extends State<LogMealScreen>
onCalendar: onOpenCalendar, onCalendar: onOpenCalendar,
onSettings: onOpenSettings, onSettings: onOpenSettings,
onBody: onOpenBody, onBody: onOpenBody,
leading: buildDateActions(context),
), ),
), ),
body: SafeArea( body: SafeArea(
@ -187,11 +190,7 @@ class _LogMealScreenState extends State<LogMealScreen>
child: Column( child: Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
if (!due) ...[ if (!due) SyncHealthBanner(status: syncHealth),
SyncHealthBanner(status: syncHealth),
buildWhenRow(context),
const SizedBox(height: AppSpacing.sm),
],
buildSlotRow(), buildSlotRow(),
Opacity( Opacity(
opacity: dim ? 0.5 : 1, opacity: dim ? 0.5 : 1,
@ -231,13 +230,14 @@ class _LogMealScreenState extends State<LogMealScreen>
onSend: sendToClaude, onSend: sendToClaude,
onLog: _onLogMeal, onLog: _onLogMeal,
), ),
for (final meal in loggedRows) if (!typing)
LoggedMealRow(meal: meal, onUndo: () => undoLogged(meal)), for (final meal in loggedRows)
LoggedMealRow(meal: meal, onUndo: () => undoLogged(meal)),
if (_cue != null) ...[ if (_cue != null) ...[
const SizedBox(height: AppSpacing.sm), const SizedBox(height: AppSpacing.sm),
_cue!.widget, _cue!.widget,
], ],
if (_progress != null && !due) ...[ if (_progress != null && !due && !typing) ...[
const SizedBox(height: AppSpacing.sm), const SizedBox(height: AppSpacing.sm),
TodayProgressCard(progress: _progress!), TodayProgressCard(progress: _progress!),
], ],

View File

@ -54,7 +54,7 @@ void main() {
await open(tester); await open(tester);
expect(find.byType(AppBar), findsNothing); expect(find.byType(AppBar), findsNothing);
expect(find.byType(SyncHealthBanner), findsNothing); expect(find.byType(SyncHealthBanner), findsNothing);
expect(find.byIcon(Icons.date_range), findsNothing); expect(find.byIcon(Icons.edit_calendar), findsNothing);
expect(find.byType(ChoiceChip), findsNothing); expect(find.byType(ChoiceChip), findsNothing);
expect(find.byIcon(Icons.playlist_add_check), findsNothing); expect(find.byIcon(Icons.playlist_add_check), findsNothing);
// What stays: field, six macro fields, the three buttons. // What stays: field, six macro fields, the three buttons.
@ -71,7 +71,7 @@ void main() {
await tester.runAsync(() async { await tester.runAsync(() async {
await open(tester); await open(tester);
expect(find.byType(AppBar), findsOneWidget); expect(find.byType(AppBar), findsOneWidget);
expect(find.byIcon(Icons.date_range), findsOneWidget); expect(find.byIcon(Icons.edit_calendar), findsOneWidget);
expect(find.byType(ChoiceChip), findsNothing); expect(find.byType(ChoiceChip), findsNothing);
expect(find.byIcon(Icons.playlist_add_check), findsNothing); expect(find.byIcon(Icons.playlist_add_check), findsNothing);
expect(byIconLabel('Photo'), findsOneWidget); expect(byIconLabel('Photo'), findsOneWidget);

View File

@ -122,7 +122,9 @@ void main() {
), ),
); );
await settle(tester); await settle(tester);
expect(find.byIcon(Icons.undo), findsOneWidget); // The logged row collapses while the keyboard is up (no cover by
// keyboard); log_meal_keyboard_test.dart covers it coming back.
expect(find.byIcon(Icons.undo), findsNothing);
// Still due (12:00 is open): the screen stays in due mode. // Still due (12:00 is open): the screen stays in due mode.
expect(find.byType(AppBar), findsNothing); expect(find.byType(AppBar), findsNothing);
await fillWorstCase(tester); await fillWorstCase(tester);

View File

@ -0,0 +1,170 @@
/// kuhy's hard rule, 2026-11-17: NO COVER BY KEYBOARD EVER. With the keyboard
/// open the today-progress card and the logged rows collapse, so the field,
/// suggestions, macro fields and action row all sit above it with no scroll.
/// Also the date picker's move into the app bar and its picked-date tint.
library;
import 'package:diet_guard_app/screens/log_meal_screen.dart';
import 'package:diet_guard_app/widgets/logged_meal_row.dart';
import 'package:diet_guard_app/widgets/meal_action_row.dart';
import 'package:diet_guard_app/widgets/today_progress_card.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:material_ui/material_ui.dart';
import '../label_finders.dart';
import 'log_meal_test_support.dart';
const double _dpr = 2.625;
void _phone(WidgetTester tester, {required double keyboardPx}) {
tester.view
..physicalSize = const Size(1080, 2400)
..devicePixelRatio = _dpr
..padding = const FakeViewPadding(top: 132, bottom: 63)
..viewPadding = const FakeViewPadding(top: 132, bottom: 63)
..viewInsets = FakeViewPadding(bottom: keyboardPx);
}
double _maxScroll(WidgetTester tester) => tester
.state<ScrollableState>(
find
.descendant(
of: find.byType(SingleChildScrollView),
matching: find.byType(Scrollable),
)
.first,
)
.position
.maxScrollExtent;
/// Every widget the form shows ends above the keyboard, the action row is
/// tappable, and nothing scrolls.
void _expectAboveKeyboard(WidgetTester tester, double keyboardPx) {
final keyboardTop = (2400 - keyboardPx) / _dpr;
for (final type in <Type>[
TextField,
MealActionRow,
LoggedMealRow,
TodayProgressCard,
]) {
for (final e in find.byType(type).evaluate()) {
final box = e.renderObject! as RenderBox;
final bottom = box.localToGlobal(Offset(0, box.size.height)).dy;
expect(bottom, lessThanOrEqualTo(keyboardTop), reason: '$type covered');
}
}
expect(controlByLabel('Log meal').hitTestable(), findsOneWidget);
expect(controlByLabel('Photo').hitTestable(), findsOneWidget);
expect(_maxScroll(tester), 0, reason: 'the form scrolls');
}
void main() {
late Future<void> Function() restore;
setUp(() async => restore = await isolateLogScreenState());
tearDown(() => restore());
Future<void> open(WidgetTester tester) async {
await tester.pumpWidget(const MaterialApp(home: LogMealScreen()));
await settle(tester);
}
Future<void> fillWorstCase(WidgetTester tester, String name) async {
await tester.enterText(find.byType(TextField).at(0), name);
final worst = ['1250', '2400', '1234', '1234', '1234', '1234'];
for (var i = 0; i < worst.length; i++) {
await tester.enterText(find.byType(TextField).at(i + 1), worst[i]);
}
await settle(tester);
}
for (final kb in [840.0, 1050.0]) {
testWidgets('normal mode, keyboard $kb px: nothing under it', (
tester,
) async {
addTearDown(tester.view.reset);
_phone(tester, keyboardPx: 0);
await tester.runAsync(() async {
await open(tester);
await fillWorstCase(tester, 'kurczak z ryzem');
await tester.tap(controlByLabel('Log meal'));
await settle(tester);
// Keyboard closed: the card and the logged row are both there.
expect(find.byType(TodayProgressCard), findsOneWidget);
expect(find.byType(LoggedMealRow), findsOneWidget);
_phone(tester, keyboardPx: kb);
await fillWorstCase(tester, 'kurczak');
expect(find.byType(TodayProgressCard), findsNothing);
expect(find.byType(LoggedMealRow), findsNothing);
_expectAboveKeyboard(tester, kb);
_phone(tester, keyboardPx: 0);
await settle(tester);
expect(find.byType(LoggedMealRow), findsOneWidget);
});
});
testWidgets('due mode, keyboard $kb px: nothing under it', (tester) async {
addTearDown(tester.view.reset);
_phone(tester, keyboardPx: kb);
pinLogMealClock(13);
await tester.runAsync(() async {
await open(tester);
await fillWorstCase(tester, 'kurczak z ryzem');
expect(find.byType(AppBar), findsNothing);
_expectAboveKeyboard(tester, kb);
});
});
}
group('date picker in the app bar', () {
Color tint(WidgetTester tester) {
final icon = find.byIcon(Icons.edit_calendar);
return tester.widget<Icon>(icon).color ??
IconTheme.of(tester.element(icon)).color!;
}
testWidgets('leftmost action; no row above the field', (tester) async {
await tester.runAsync(() async {
await open(tester);
final date = find.byIcon(Icons.edit_calendar);
expect(
find.descendant(of: find.byType(AppBar), matching: date),
findsOneWidget,
);
expect(find.byIcon(Icons.date_range), findsNothing);
final x = tester.getCenter(date).dx;
for (final other in [Icons.monitor_weight, Icons.settings]) {
expect(x, lessThan(tester.getCenter(find.byIcon(other)).dx));
}
});
});
testWidgets('a picked future date tints the icon gold with a dot', (
tester,
) async {
await tester.runAsync(() async {
await open(tester);
final gold = Theme.of(
tester.element(find.byType(AppBar)),
).colorScheme.primary;
const badge = ValueKey<String>('log-date-badge');
expect(tint(tester), isNot(gold));
expect(find.byKey(badge), findsNothing);
await tester.tap(controlByLabel('Log for later'));
await settle(tester);
await tester.tap(controlByLabel('Confirm'));
await settle(tester);
expect(tint(tester), gold);
expect(find.byKey(badge), findsOneWidget);
final dates = find.textContaining(RegExp(r'^\d{4}-\d{2}-\d{2}$'));
expect(dates, findsNothing, reason: 'no painted date');
await tester.tap(controlByLabel('Back to today'));
await settle(tester);
expect(find.byKey(badge), findsNothing);
});
});
});
}

View File

@ -68,7 +68,7 @@ void main() {
await settle(tester); await settle(tester);
final tomorrowKey = localDateKey(tomorrow()); final tomorrowKey = localDateKey(tomorrow());
expect(find.text(tomorrowKey), findsOneWidget); expect(byIconLabel('Change date'), findsOneWidget);
final firstSlot = daySlots(MealScheduleService.current).first; final firstSlot = daySlots(MealScheduleService.current).first;
await tester.tap(find.text(slotLabel(firstSlot))); await tester.tap(find.text(slotLabel(firstSlot)));
@ -91,7 +91,7 @@ void main() {
expect(future.time.startsWith(tomorrowKey), isTrue); expect(future.time.startsWith(tomorrowKey), isTrue);
// Back to logging for today. // Back to logging for today.
expect(find.text(tomorrowKey), findsNothing); expect(byIconLabel('Change date'), findsNothing);
expect(controlByLabel('Log for later'), findsOneWidget); expect(controlByLabel('Log for later'), findsOneWidget);
}); });
}, },
@ -133,12 +133,12 @@ void main() {
await settle(tester); await settle(tester);
await tester.tap(controlByLabel('Confirm')); await tester.tap(controlByLabel('Confirm'));
await settle(tester); await settle(tester);
expect(find.text(localDateKey(tomorrow())), findsOneWidget); expect(byIconLabel('Change date'), findsOneWidget);
await tester.tap(controlByLabel('Back to today')); await tester.tap(controlByLabel('Back to today'));
await settle(tester); await settle(tester);
expect(find.text(localDateKey(tomorrow())), findsNothing); expect(byIconLabel('Change date'), findsNothing);
expect(controlByLabel('Log for later'), findsOneWidget); expect(controlByLabel('Log for later'), findsOneWidget);
}); });
}); });

View File

@ -22,7 +22,7 @@ Until the first read of today's log the screen draws neither (no app-bar flash).
No slot picker. Due mode: both the check and the sparkle target the **oldest No slot picker. Due mode: both the check and the sparkle target the **oldest
due slot** (`dueSlots.first`). Normal mode: `slotForLog` (nearest). The integer due slot** (`dueSlots.first`). Normal mode: `slotForLog` (nearest). The integer
slot maths in `models/slot.dart` is untouched. A *future* date (the date row, slot maths in `models/slot.dart` is untouched. A *future* date (the app bar's date icon,
normal mode only) keeps its own slot row, because it has no due slots to derive normal mode only) keeps its own slot row, because it has no due slots to derive
from. from.
@ -42,6 +42,19 @@ every state and `maxScrollExtent == 0`. Macro values of four digits must paint
whole at 16 sp or more (`macro_input_row_test.dart` measures the digits; a whole at 16 sp or more (`macro_input_row_test.dart` measures the digits; a
`Row` of `Expanded` fields clips them without any exception). `Row` of `Expanded` fields clips them without any exception).
## Date picker and the keyboard
- The "log for later" picker is the **leftmost app bar icon** (`Icons.edit_calendar`,
`buildDateActions` in `log_meal_future_mixin.dart`); there is no date row above
the field. A picked future date tints it gold (theme primary) with a small
dot (`log-date-badge`) and adds a close icon back to today. No date text.
- **NO COVER BY KEYBOARD EVER** (kuhy): while `viewInsetsOf(context).bottom > 0`
the today-progress card and the logged rows are not built; they return when
the keyboard closes. Field, suggestions, macros and action row sit fully
above the keyboard with `maxScrollExtent == 0`, in normal and due mode, for
a 320 dp and a 400 dp keyboard (`log_meal_keyboard_test.dart`). Do not fix
an overflow by scrolling content under the keyboard.
## Logged rows and undo ## Logged rows and undo
After a Claude, check or catering log, a row (origin glyph, name, kcal and macro After a Claude, check or catering log, a row (origin glyph, name, kcal and macro