DatePicker constructor

DatePicker({
  1. Key? key,
  2. required DateTime? initialDate,
  3. required DateTime firstDate,
  4. required DateTime lastDate,
  5. DateTime? currentDate,
  6. required ValueChanged<DateTime> onDateChanged,
  7. DatePickerController? controller,
  8. ValueChanged<DateTime>? onDisplayedMonthChanged,
  9. Color? enableTextColor,
  10. Color? disableTextColor,
  11. Color? selectedTextColor,
  12. Color? selectedColor,
  13. Color? backgroundColor,
  14. TextStyle? monthTextStyle,
  15. double? monthHeaderItemHeight,
  16. BoxShape selectedShape = BoxShape.circle,
  17. SelectableDayPredicate? selectableDayPredicate,
})

Implementation

DatePicker({
  super.key,
  required DateTime? initialDate,
  required DateTime firstDate,
  required DateTime lastDate,
  DateTime? currentDate,
  required this.onDateChanged,
  this.controller,
  this.onDisplayedMonthChanged,
  this.enableTextColor,
  this.disableTextColor,
  this.selectedTextColor,
  this.selectedColor,
  this.backgroundColor,
  this.monthTextStyle,
  this.monthHeaderItemHeight,
  this.selectedShape = BoxShape.circle,
  this.selectableDayPredicate,
})  : initialDate =
          initialDate == null ? null : DateUtils.dateOnly(initialDate),
      firstDate = DateUtils.dateOnly(firstDate),
      lastDate = DateUtils.dateOnly(lastDate),
      currentDate = DateUtils.dateOnly(currentDate ?? DateTime.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.',
  );
}