screen-locker/stronglift_replacement/workout_app/lib/widgets/calendar_widget.dart
Krzysztof kuhy Rudnicki 5f2925a550 Move workout_app to Flutter 3.50 material_ui
Flutter 3.50 deprecates package:flutter/material.dart, which made
flutter-analyze report 27 deprecated_member_use infos and blocked the
gate. workout_app now imports material_ui 1.11.0, with crdt_sync_dart
0.14.1 and sync_settings_ui 0.8.2 (both on material_ui).

material_ui's MaterialApp ships its own MaterialLocalizations, so a
package that still calls the framework showDialog threw a null check.
WorkoutApp now adds the framework delegate, and a widget test opens a
material_ui and a framework dialog through the real app root.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WzxdWWfb63jncj9Lca2jeX
2026-11-16 08:54:33 +01:00

169 lines
5.6 KiB
Dart

/// Monthly calendar showing which days had workouts.
library;
import 'package:material_ui/material_ui.dart';
import 'package:workout_app/ui/theme.dart';
/// Monthly calendar widget that highlights days with completed workouts.
class WorkoutCalendar extends StatelessWidget {
/// Creates a [WorkoutCalendar].
const WorkoutCalendar({
required this.workoutDates,
required this.month,
required this.onPrevMonth,
required this.onNextMonth,
super.key,
});
/// Set of YYYY-MM-DD date strings that had at least one workout.
final Set<String> workoutDates;
/// Only the year and month of this DateTime are used.
final DateTime month;
/// Called when the user taps the previous-month chevron.
final VoidCallback onPrevMonth;
/// Called when the user taps the next-month chevron.
final VoidCallback onNextMonth;
// textgate: weekday headers are dots (weekend dots hollow) and the
// month header is `08.2026`; the old words are spoken only.
static const _weekdaySemanticsLabels = [
'Monday',
'Tuesday',
'Wednesday',
'Thursday',
'Friday',
'Saturday',
'Sunday',
];
String _dateKey(int year, int m, int day) =>
'$year-${m.toString().padLeft(2, '0')}-${day.toString().padLeft(2, '0')}';
@override
Widget build(BuildContext context) {
final colorScheme = Theme.of(context).colorScheme;
final status = Theme.of(context).extension<AppStatusColors>()!;
final year = month.year;
final m = month.month;
final daysInMonth = DateTime(year, m + 1, 0).day;
// weekday: 1=Mon..7=Sun → offset 0..6
final firstWeekday = DateTime(year, m).weekday - 1;
final totalCells = firstWeekday + daysInMonth;
final rows = (totalCells / 7).ceil();
return Container(
padding: const EdgeInsets.all(12),
decoration: BoxDecoration(
color: colorScheme.surfaceContainerHigh,
borderRadius: BorderRadius.circular(AppRadius.sm),
),
child: Column(
children: [
// Month navigation header
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
IconButton(
icon: Icon(
Icons.chevron_left,
color: colorScheme.onSurfaceVariant,
),
visualDensity: VisualDensity.compact,
padding: EdgeInsets.zero,
onPressed: onPrevMonth,
),
Text(
'${m.toString().padLeft(2, '0')}.$year',
style: TextStyle(
color: colorScheme.onSurface,
fontWeight: FontWeight.bold,
fontSize: AppTextSize.label,
),
),
IconButton(
icon: Icon(
Icons.chevron_right,
color: colorScheme.onSurfaceVariant,
),
visualDensity: VisualDensity.compact,
padding: EdgeInsets.zero,
onPressed: onNextMonth,
),
],
),
const SizedBox(height: 6),
// Day-of-week headers
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
for (var i = 0; i < 7; i++)
SizedBox(
width: 30,
child: Semantics(
label: _weekdaySemanticsLabels[i],
child: Center(
child: Container(
width: 6,
height: 6,
decoration: BoxDecoration(
shape: BoxShape.circle,
// Weekend: hollow ring; weekday: filled dot.
color: i >= 5 ? null : colorScheme.onSurfaceVariant,
border: Border.all(
color: colorScheme.onSurfaceVariant,
),
),
),
),
),
),
],
),
const SizedBox(height: 4),
// Day grid
...List.generate(rows, (row) {
return Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: List.generate(7, (col) {
final cell = row * 7 + col;
final day = cell - firstWeekday + 1;
if (day < 1 || day > daysInMonth) {
return const SizedBox(width: 30, height: 30);
}
final key = _dateKey(year, m, day);
final worked = workoutDates.contains(key);
return Container(
width: 30,
height: 30,
margin: const EdgeInsets.symmetric(vertical: 2),
decoration: worked
? BoxDecoration(
shape: BoxShape.circle,
color: status.success,
)
: null,
alignment: Alignment.center,
child: Text(
'$day',
style: TextStyle(
// on-fill (dark) on the success circle, muted otherwise.
color: worked
? colorScheme.onPrimary
: colorScheme.onSurfaceVariant,
fontSize: AppTextSize.caption,
fontWeight: worked ? FontWeight.bold : FontWeight.normal,
),
),
);
}),
);
}),
],
),
);
}
}