DatePickerDialog constructor Null safety
- {Key? key,
- required DateTime initialDate,
- required DateTime firstDate,
- required DateTime lastDate,
- DateTime? currentDate,
- DatePickerEntryMode initialEntryMode = DatePickerEntryMode.calendar,
- SelectableDayPredicate? selectableDayPredicate,
- String? cancelText,
- String? confirmText,
- String? helpText,
- DatePickerMode initialCalendarMode = DatePickerMode.day,
- String? errorFormatText,
- String? errorInvalidText,
- String? fieldHintText,
- String? fieldLabelText,
- TextInputType? keyboardType,
- String? restorationId}
A Material-style date picker dialog.
Implementation
DatePickerDialog({
super.key,
required DateTime initialDate,
required DateTime firstDate,
required DateTime lastDate,
DateTime? currentDate,
this.initialEntryMode = DatePickerEntryMode.calendar,
this.selectableDayPredicate,
this.cancelText,
this.confirmText,
this.helpText,
this.initialCalendarMode = DatePickerMode.day,
this.errorFormatText,
this.errorInvalidText,
this.fieldHintText,
this.fieldLabelText,
this.keyboardType,
this.restorationId,
}) : assert(initialDate != null),
assert(firstDate != null),
assert(lastDate != null),
initialDate = DateUtils.dateOnly(initialDate),
firstDate = DateUtils.dateOnly(firstDate),
lastDate = DateUtils.dateOnly(lastDate),
currentDate = DateUtils.dateOnly(currentDate ?? DateTime.now()),
assert(initialEntryMode != null),
assert(initialCalendarMode != null) {
assert(
!this.lastDate.isBefore(this.firstDate),
'lastDate ${this.lastDate} must be on or after firstDate ${this.firstDate}.',
);
assert(
!this.initialDate.isBefore(this.firstDate),
'initialDate ${this.initialDate} must be on or after firstDate ${this.firstDate}.',
);
assert(
!this.initialDate.isAfter(this.lastDate),
'initialDate ${this.initialDate} must be on or before lastDate ${this.lastDate}.',
);
assert(
selectableDayPredicate == null || selectableDayPredicate!(this.initialDate),
'Provided initialDate ${this.initialDate} must satisfy provided selectableDayPredicate',
);
}