build method
Describes the part of the UI represented by this widget.
Implementation
@override
Widget build(BuildContext context) {
final theme = ThemeScope.of(context);
final visibleMonth = DateTime(month.year, month.month);
final currentDay = _dateOnly(today ?? DateTime.now());
final selected = selectedDate == null ? null : _dateOnly(selectedDate!);
final normalizedMarkers = <DateTime, String>{
for (final entry in markers.entries)
_dateOnly(entry.key): entry.value.isEmpty ? '•' : entry.value[0],
};
final normal = dayStyle ?? theme.bodyMedium;
final outside =
outsideStyle ?? (copyStyle(normal)..foreground(theme.muted));
final todayCell =
todayStyle ??
(copyStyle(normal)
..foreground(theme.primary)
..bold());
final selectedCell =
selectedStyle ??
(copyStyle(normal)
..foreground(theme.onPrimary)
..background(theme.primary)
..bold());
final weekdays = _orderedWeekdays(firstDayOfWeek);
final cells = _monthCells(visibleMonth, firstDayOfWeek);
final rows = <Widget>[
Text(
'${_monthNames[visibleMonth.month - 1]} ${visibleMonth.year}',
style: headerStyle ?? theme.titleSmall,
),
Row(
gap: 0,
children: [
for (final weekday in weekdays)
Text(weekday.padRight(3), style: weekdayStyle ?? theme.labelSmall),
],
),
];
for (var week = 0; week < cells.length; week += 7) {
rows.add(
Row(
gap: 0,
children: [
for (final date in cells.skip(week).take(7))
_buildDay(
date,
visibleMonth,
currentDay,
selected,
normalizedMarkers,
normal,
outside,
todayCell,
selectedCell,
),
],
),
);
}
return Column(gap: 0, children: rows);
}