onChangeDate function

void onChangeDate({
  1. required DateTime currentDate,
  2. required StreamController<DateTime> dateStreamController,
  3. int? day,
  4. int? month,
  5. int? year,
})

Callback for when any dropdown changes a date Handling date conflicts

Implementation

void onChangeDate({
  required DateTime currentDate,
  required StreamController<DateTime> dateStreamController,
  int? day,
  int? month,
  int? year,
}) {
  if (!dateStreamController.isClosed) {
    int lastDayOfMonth = getNoOfDaysInMonth(
      year: year ?? currentDate.year,
      month: month ?? currentDate.month,
    );

    day ??= currentDate.day;

    if (day > lastDayOfMonth) {
      day = lastDayOfMonth;
    }

    currentDate = currentDate.copyWith(day: day, month: month, year: year);
    dateStreamController.sink.add(currentDate);
  }
}