InputDatePickerFormField constructor Null safety

InputDatePickerFormField(
  1. {Key? key,
  2. DateTime? initialDate,
  3. required DateTime firstDate,
  4. required DateTime lastDate,
  5. ValueChanged<DateTime>? onDateSubmitted,
  6. ValueChanged<DateTime>? onDateSaved,
  7. SelectableDayPredicate? selectableDayPredicate,
  8. String? errorFormatText,
  9. String? errorInvalidText,
  10. String? fieldHintText,
  11. String? fieldLabelText,
  12. TextInputType? keyboardType,
  13. bool autofocus = false}
)

Creates a TextFormField configured to accept and validate a date.

If the optional initialDate is provided, then it will be used to populate the text field. If the fieldHintText is provided, it will be shown.

If initialDate is provided, it must not be before firstDate or after lastDate. If selectableDayPredicate is provided, it must return true for initialDate.

firstDate must be on or before lastDate.

firstDate, lastDate, and autofocus must be non-null.

Implementation

InputDatePickerFormField({
  super.key,
  DateTime? initialDate,
  required DateTime firstDate,
  required DateTime lastDate,
  this.onDateSubmitted,
  this.onDateSaved,
  this.selectableDayPredicate,
  this.errorFormatText,
  this.errorInvalidText,
  this.fieldHintText,
  this.fieldLabelText,
  this.keyboardType,
  this.autofocus = false,
}) : assert(firstDate != null),
     assert(lastDate != null),
     assert(autofocus != null),
     initialDate = initialDate != null ? DateUtils.dateOnly(initialDate) : null,
     firstDate = DateUtils.dateOnly(firstDate),
     lastDate = DateUtils.dateOnly(lastDate) {
  assert(
    !this.lastDate.isBefore(this.firstDate),
    'lastDate ${this.lastDate} must be on or after firstDate ${this.firstDate}.',
  );
  assert(
    initialDate == null || !this.initialDate!.isBefore(this.firstDate),
    'initialDate ${this.initialDate} must be on or after firstDate ${this.firstDate}.',
  );
  assert(
    initialDate == null || !this.initialDate!.isAfter(this.lastDate),
    'initialDate ${this.initialDate} must be on or before lastDate ${this.lastDate}.',
  );
  assert(
    selectableDayPredicate == null || initialDate == null || selectableDayPredicate!(this.initialDate!),
    'Provided initialDate ${this.initialDate} must satisfy provided selectableDayPredicate.',
  );
}