Calendar constructor
const
Calendar({
- Key? key,
- DateTime? now,
- CalendarValue? value,
- required CalendarView view,
- required CalendarSelectionMode selectionMode,
- ValueChanged<
CalendarValue?> ? onChanged, - bool isDateEnabled(
- DateTime date
- DateStateBuilder? stateBuilder,
Creates a Calendar widget with flexible date selection capabilities.
Configures the calendar's view, selection behavior, and interaction handling with comprehensive options for customization and validation.
Parameters:
view(CalendarView, required): Month/year to display in calendar gridselectionMode(CalendarSelectionMode, required): How dates can be selectednow(DateTime?, optional): Current date for highlighting, defaults to DateTime.now()value(CalendarValue?, optional): Currently selected date(s)onChanged(ValueChanged<CalendarValue?>?, optional): Called when selection changesisDateEnabled(bool Function(DateTime)?, optional): Legacy date validation functionstateBuilder(DateStateBuilder?, optional): Custom date state validation
The view parameter determines which month and year are shown in the calendar grid.
Use CalendarView.now() for current month or CalendarView(year, month) for specific dates.
The stateBuilder takes precedence over isDateEnabled when both are provided.
Example:
Calendar(
view: CalendarView(2024, 3), // March 2024
selectionMode: CalendarSelectionMode.single,
onChanged: (value) => print('Selected: ${value?.toString()}'),
stateBuilder: (date) => date.weekday == DateTime.sunday
? DateState.disabled
: DateState.enabled,
)
Implementation
const Calendar({
super.key,
this.now,
this.value,
required this.view,
required this.selectionMode,
this.onChanged,
this.isDateEnabled,
this.stateBuilder,
});