Calendar constructor

const Calendar({
  1. Key? key,
  2. DateTime? now,
  3. CalendarValue? value,
  4. required CalendarView view,
  5. required CalendarSelectionMode selectionMode,
  6. ValueChanged<CalendarValue?>? onChanged,
  7. bool isDateEnabled(
    1. DateTime date
    )?,
  8. 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 grid
  • selectionMode (CalendarSelectionMode, required): How dates can be selected
  • now (DateTime?, optional): Current date for highlighting, defaults to DateTime.now()
  • value (CalendarValue?, optional): Currently selected date(s)
  • onChanged (ValueChanged<CalendarValue?>?, optional): Called when selection changes
  • isDateEnabled (bool Function(DateTime)?, optional): Legacy date validation function
  • stateBuilder (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,
});