DaysPicker constructor

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

Creates a days 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 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

DaysPicker({
  super.key,
  required this.maxDate,
  required this.minDate,
  this.initialDate,
  this.currentDate,
  this.selectedDate,
  this.daysOfTheWeekTextStyle,
  this.enabledCellsTextStyle,
  this.enabledCellsDecoration = const BoxDecoration(),
  this.disabledCellsTextStyle,
  this.disabledCellsDecoration = const BoxDecoration(),
  this.currentDateTextStyle,
  this.currentDateDecoration,
  this.selectedCellTextStyle,
  this.selectedCellDecoration,
  this.onLeadingDateTap,
  this.onDateSelected,
  this.leadingDateTextStyle,
  this.slidersColor,
  this.slidersSize,
  this.highlightColor,
  this.splashColor,
  this.splashRadius,
  this.centerLeadingDate = false,
  this.previousPageSemanticLabel = 'Previous Day',
  this.nextPageSemanticLabel = 'Next Day',
  this.disabledDayPredicate,
}) {
  assert(!minDate.isAfter(maxDate), "minDate can't be after maxDate");
  assert(
    () {
      if (initialDate == null) return true;
      final init = DateTime(initialDate!.year, initialDate!.month, initialDate!.day);

      final min = DateTime(minDate.year, minDate.month, minDate.day);

      return init.isAfter(min) || init.isAtSameMomentAs(min);
    }(),
    'initialDate $initialDate must be on or after minDate $minDate.',
  );
  assert(
    () {
      if (initialDate == null) return true;
      final init = DateTime(initialDate!.year, initialDate!.month, initialDate!.day);

      final max = DateTime(maxDate.year, maxDate.month, maxDate.day);
      return init.isBefore(max) || init.isAtSameMomentAs(max);
    }(),
    'initialDate $initialDate must be on or before maxDate $maxDate.',
  );
}