diet-guard/app/lib/widgets/pickers/date_grid.dart
Krzysztof kuhy Rudnicki 49144a2c49 Move the app to material_ui for Flutter 3.50
Flutter 3.50 deprecates package:flutter/material.dart; 73 deprecation
infos failed flutter analyze --fatal-infos, and four Dart pins were
behind (crdt_sync_flutter 0.8.2, flutter_local_notifications 23.0.2,
github_device_auth 0.5.0, sync_settings_ui 0.8.2). Those UI packages
now sit on material_ui, so the app has to as well or their widgets lose
MaterialLocalizations.

Imports swap one-for-one and dart fix re-sorted the directives; no
behaviour change. analyze is clean and all six test shards pass.

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

75 lines
2.5 KiB
Dart

/// The day grid: one month of numerals, Monday first, with no weekday header.
///
/// One widget serves the single-date and the range picker; the mode lives in
/// [DateSelection], so the range picker is a mode of this grid, not a copy.
library;
import 'package:diet_guard_app/widgets/pickers/date_selection.dart';
import 'package:diet_guard_app/widgets/pickers/numeral_cell.dart';
import 'package:material_ui/material_ui.dart';
/// Six rows of seven: every month fits, and the dialog never changes height.
const int kGridCells = 42;
/// The shown month of [selection] as a numeral grid.
///
/// Today has a ring; weekends are dimmed with a dot; out-of-range days are
/// dimmed further and inert. The chosen day, or both range ends, are filled;
/// the days of a range are shaded.
class DateGrid extends StatelessWidget {
/// Creates a [DateGrid].
const DateGrid({
required this.selection,
required this.today,
required this.onTap,
this.showCursor = false,
super.key,
});
/// The selection being edited (read only here).
final DateSelection selection;
/// Today's date, ringed.
final DateTime today;
/// Called with a tapped in-range day.
final ValueChanged<DateTime> onTap;
/// Whether to outline the keyboard cursor (the grid has focus).
final bool showCursor;
bool _inBand(DateTime day) {
final start = selection.start;
final end = selection.end;
if (start == null || end == null || start == end) return false;
return !day.isBefore(start) && !day.isAfter(end);
}
@override
Widget build(BuildContext context) {
final l10n = MaterialLocalizations.of(context);
final year = selection.year;
final month = selection.month;
final lead = DateTime(year, month).weekday - DateTime.monday;
final days = DateUtils.getDaysInMonth(year, month);
return numeralRows(7, [
for (var i = 0; i < lead; i++) const SizedBox.shrink(),
for (var d = 1; d <= days; d++) _cell(DateTime(year, month, d), l10n),
for (var i = lead + days; i < kGridCells; i++) const SizedBox.shrink(),
]);
}
Widget _cell(DateTime day, MaterialLocalizations l10n) => NumeralCell(
key: ValueKey(day),
label: '${day.day}',
semanticLabel: l10n.formatFullDate(day),
onTap: () => onTap(day),
enabled: selection.allows(day),
selected: day == selection.start || day == selection.end,
band: _inBand(day),
ring: DateUtils.isSameDay(day, today),
dot: day.weekday >= DateTime.saturday,
focused: showCursor && day == selection.cursor,
);
}