CalendarDatePicker2 constructor

CalendarDatePicker2({
  1. required CalendarDatePicker2Config config,
  2. required List<DateTime?> value,
  3. ValueChanged<List<DateTime?>>? onValueChanged,
  4. Future onChange()?,
  5. DateTime? displayedMonthDate,
  6. ValueChanged<DateTime>? onDisplayedMonthChanged,
  7. Key? key,
})

Implementation

CalendarDatePicker2({
  required this.config,
  required this.value,
  this.onValueChanged,
  // this.onDatesChanged,
  this.onChange,
  this.displayedMonthDate,
  this.onDisplayedMonthChanged,
  Key? key,
}) : super(key: key) {
  const valid = true;
  const invalid = false;

  if (config.calendarType == CalendarDatePicker2Type.single) {
    assert(value.length < 2,
        'Error: single date picker only allows maximum one initial date');
  }

  if (config.calendarType == CalendarDatePicker2Type.range &&
      value.length > 1) {
    final isRangePickerValueValid = value[0] == null
        ? (value[1] != null ? invalid : valid)
        : (value[1] != null
            ? (value[1]!.isBefore(value[0]!) ? invalid : valid)
            : valid);

    assert(
      isRangePickerValueValid,
      'Error: range date picker must has start date set before setting end date, and start date must before end date.',
    );
  }
}