PersianCalendarDatePicker constructor
- Key? key,
- required Jalali? initialDate,
- required Jalali firstDate,
- required Jalali lastDate,
- Jalali? currentDate,
- required ValueChanged<
Jalali> onDateChanged, - ValueChanged<
Jalali> ? onDisplayedMonthChanged, - PersianDatePickerMode initialCalendarMode = PersianDatePickerMode.day,
- PersianSelectableDayPredicate? selectableDayPredicate,
Creates a calendar date picker.
It will display a grid of days for the initialDate
's month, or, if that
is null, the currentDate
's month. The day indicated by initialDate
will
be selected if it is not null.
The optional onDisplayedMonthChanged
callback can be used to track
the currently displayed month.
The user interface provides a way to change the year of the month being
displayed. By default it will show the day grid, but this can be changed
to start in the year selection interface with initialCalendarMode
set
to PersianDatePickerMode.year.
The lastDate
must be after or equal to firstDate
.
The initialDate
, if provided, must be between firstDate
and lastDate
or 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
Jalali.now()
will be used.
If selectableDayPredicate
and initialDate
are both non-null,
selectableDayPredicate
must return true
for the initialDate
.
Implementation
PersianCalendarDatePicker({
super.key,
required Jalali? initialDate,
required Jalali firstDate,
required Jalali lastDate,
Jalali? currentDate,
required this.onDateChanged,
this.onDisplayedMonthChanged,
this.initialCalendarMode = PersianDatePickerMode.day,
this.selectableDayPredicate,
}) : initialDate = initialDate == null ? null : PersianDateUtils.dateOnly(initialDate),
firstDate = PersianDateUtils.dateOnly(firstDate),
lastDate = PersianDateUtils.dateOnly(lastDate),
currentDate = PersianDateUtils.dateOnly(currentDate ?? Jalali.now()) {
assert(
!this.lastDate.isBefore(this.firstDate),
'lastDate ${this.lastDate} must be on or after firstDate ${this.firstDate}.',
);
assert(
this.initialDate == null || !this.initialDate!.isBefore(this.firstDate),
'initialDate ${this.initialDate} must be on or after firstDate ${this.firstDate}.',
);
assert(
this.initialDate == null || !this.initialDate!.isAfter(this.lastDate),
'initialDate ${this.initialDate} must be on or before lastDate ${this.lastDate}.',
);
assert(
selectableDayPredicate == null || this.initialDate == null || selectableDayPredicate!(this.initialDate!),
'Provided initialDate ${this.initialDate} must satisfy provided selectableDayPredicate.',
);
}