onDateClick method

void onDateClick(
  1. DateTime date
)

Implementation

void onDateClick(DateTime date) {
  if (startDate == null) {
    startDate = date;
  } else if (startDate != date && endDate == null) {
    endDate = date;
  } else if (startDate!.day == date.day && startDate!.month == date.month) {
    startDate = null;
  } else if (endDate!.day == date.day && endDate!.month == date.month) {
    endDate = null;
  }
  if (startDate == null && endDate != null) {
    startDate = endDate;
    endDate = null;
  }
  if (startDate != null && endDate != null) {
    if (!endDate!.isAfter(startDate!)) {
      final DateTime d = startDate!;
      startDate = endDate;
      endDate = d;
    }
    if (date.isBefore(startDate!)) {
      startDate = date;
    }
    if (date.isAfter(endDate!)) {
      endDate = date;
    }
  }
  setState(() {
    try {
      widget.startEndDateChange!(startDate!, endDate!);
    } catch (_) {}
  });
}