DaysPicker constructor
- Key? key,
- required DateTime maxDate,
- required DateTime minDate,
- DateTime? initialDate,
- DateTime? currentDate,
- DateTime? selectedDate,
- TextStyle? daysOfTheWeekTextStyle,
- TextStyle? enabledCellsTextStyle,
- BoxDecoration enabledCellsDecoration = const BoxDecoration(),
- TextStyle? disabledCellsTextStyle,
- BoxDecoration disabledCellsDecoration = const BoxDecoration(),
- TextStyle? currentDateTextStyle,
- BoxDecoration? currentDateDecoration,
- TextStyle? selectedCellTextStyle,
- BoxDecoration? selectedCellDecoration,
- VoidCallback? onLeadingDateTap,
- ValueChanged<
DateTime> ? onDateSelected, - TextStyle? leadingDateTextStyle,
- Color? slidersColor,
- double? slidersSize,
- Color? highlightColor,
- Color? splashColor,
- double? splashRadius,
- bool centerLeadingDate = false,
- String? previousPageSemanticLabel = 'Previous Day',
- String? nextPageSemanticLabel = 'Next Day',
- 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.',
);
}