DatePicker constructor

DatePicker({
  1. Key? key,
  2. required DateTime maxDate,
  3. required DateTime minDate,
  4. ValueChanged<DateTime>? onDateSelected,
  5. DateTime? initialDate,
  6. DateTime? selectedDate,
  7. DateTime? currentDate,
  8. EdgeInsets padding = const EdgeInsets.all(16),
  9. PickerType initialPickerType = PickerType.days,
  10. TextStyle? daysOfTheWeekTextStyle,
  11. TextStyle? enabledCellsTextStyle,
  12. BoxDecoration enabledCellsDecoration = const BoxDecoration(),
  13. TextStyle? disabledCellsTextStyle,
  14. BoxDecoration disabledCellsDecoration = const BoxDecoration(),
  15. TextStyle? currentDateTextStyle,
  16. BoxDecoration? currentDateDecoration,
  17. TextStyle? selectedCellTextStyle,
  18. BoxDecoration? selectedCellDecoration,
  19. TextStyle? leadingDateTextStyle,
  20. Color? slidersColor,
  21. double? slidersSize,
  22. Color? highlightColor,
  23. Color? splashColor,
  24. double? splashRadius,
  25. bool centerLeadingDate = false,
  26. String? previousPageSemanticLabel,
  27. String? nextPageSemanticLabel,
  28. DatePredicate? disabledDayPredicate,
})

Creates a calendar date picker.

It will display a grid of days for the initialDate's month. If initialDate is null, DateTime.now() will be used. If DateTime.now() does not fall within the valid range of minDate and maxDate, it will fall back to the nearest valid date from DateTime.now(), selecting the maxDate if DateTime.now() is after the valid range, or minDate if before.

The day indicated by selectedDate will be selected if provided.

The optional onDateSelected callback will be called if provided when a date is selected.

The user interface provides a way to change the year and the month being displayed. By default it will show the day grid, but this can be changed with initialPickerType.

The minDate is the earliest allowable date. The maxDate is the latest allowable date. initialDate and selectedDate must either fall between these dates, or be equal to one of them.

The currentDate represents the current day (i.e. today). This date will be highlighted in the day grid. If null, the date of DateTime.now() will be used.

For each of these DateTime parameters, only their dates are considered. Their time fields are ignored.

Implementation

DatePicker({
  super.key,
  required this.maxDate,
  required this.minDate,
  this.onDateSelected,
  this.initialDate,
  this.selectedDate,
  this.currentDate,
  this.padding = const EdgeInsets.all(16),
  this.initialPickerType = PickerType.days,
  this.daysOfTheWeekTextStyle,
  this.enabledCellsTextStyle,
  this.enabledCellsDecoration = const BoxDecoration(),
  this.disabledCellsTextStyle,
  this.disabledCellsDecoration = const BoxDecoration(),
  this.currentDateTextStyle,
  this.currentDateDecoration,
  this.selectedCellTextStyle,
  this.selectedCellDecoration,
  this.leadingDateTextStyle,
  this.slidersColor,
  this.slidersSize,
  this.highlightColor,
  this.splashColor,
  this.splashRadius,
  this.centerLeadingDate = false,
  this.previousPageSemanticLabel,
  this.nextPageSemanticLabel,
  this.disabledDayPredicate,
}) {
  assert(!minDate.isAfter(maxDate), "minDate can't be after maxDate");
}