wake-alarm/phone_app/lib/screens/sick_days_body.dart
Krzysztof kuhy Rudnicki 4f149e67a4 phone: read the native sick-day cache back on the Sick days screen
A release build gives no way to see the SharedPreferences cache that
AlarmReceiver reads at ring time (no run-as, no log of its contents), so
"the Dart UI shows it" could not prove "the alarm will stay silent".

- SickDays.store/dates log the sorted set under WakeAlarmSickDays.
- AlarmChannel getSickDays returns the cached set (null if unreadable).
- The Sick days screen reads it on open (before the sync rewrites it) and
  after every sync: "Alarm cache: <dates>" / "none" / "unreadable".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Xfj1sxKH9VBPqpcAni8Jry
2026-10-16 14:38:25 +02:00

93 lines
3.1 KiB
Dart

import 'package:flutter/material.dart';
import 'package:wake_alarm_sync/screens/day_calendar.dart';
import 'package:wake_alarm_sync/services/free_day_pool.dart';
import 'package:wake_alarm_sync/ui/theme.dart';
/// The sick-day picker's body: what a sick day does, the status line, the
/// month calendar and the sick days still ahead.
///
/// Stateless and fed plain values, like `FreeDaysBody`: the screen owns the
/// pool and the sync ordering, this only draws. No count and no budget --
/// sick days have none.
class SickDaysBody extends StatelessWidget {
/// Creates the body from already-resolved state.
const SickDaysBody({
required this.upcoming,
required this.status,
required this.cache,
required this.refused,
required this.calendar,
super.key,
});
/// The month grid, built by the screen, which owns the displayed month.
final DayCalendar calendar;
/// Sick days from today on, ascending.
final List<DateTime> upcoming;
/// The status line; may be a raw `Error: …`.
final String status;
/// The native ring-path cache, read back (`Alarm cache: …`).
final String cache;
/// Whether [status] is a refused tap, drawn like an error.
final bool refused;
static const _weekdays = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'];
String _label(DateTime day) =>
'${_weekdays[day.weekday - 1]} ${FreeDayPool.toIso(day)}';
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
final muted = theme.colorScheme.onSurfaceVariant;
final statusColors = theme.extension<AppStatusColors>()!;
final failed = refused || status.contains('Error');
return SafeArea(
child: ListView(
padding: const EdgeInsets.all(16),
children: [
Text(
'Tap a day to mark it sick; tap it again to clear it. Today or '
'later only. No limit and no reason needed.',
style: theme.textTheme.bodyMedium,
),
const SizedBox(height: 8),
Text(
'On a sick day the alarm stays silent, nothing locks, and work '
'left undone is dropped rather than carried forward.',
style: theme.textTheme.bodySmall?.copyWith(color: muted),
),
if (status.isNotEmpty) ...[
const SizedBox(height: 16),
Text(
status,
maxLines: 4,
overflow: TextOverflow.ellipsis,
style: TextStyle(
color: failed ? theme.colorScheme.error : statusColors.success,
),
),
],
if (cache.isNotEmpty) ...[
const SizedBox(height: 8),
Text(cache, style: TextStyle(color: muted)),
],
const SizedBox(height: 16),
calendar,
const SizedBox(height: 24),
Text('Marked sick', style: theme.textTheme.titleMedium),
const SizedBox(height: 8),
if (upcoming.isEmpty)
Text('None ahead.', style: TextStyle(color: muted)),
for (final day in upcoming)
ListTile(contentPadding: EdgeInsets.zero, title: Text(_label(day))),
],
),
);
}
}