setMonth method

void setMonth(
  1. int month
)

Implementation

void setMonth(int month) {
  if (month < 1 || month > 12) {
    return;
  }

  if (state.selectedDate != null) {
    var newDate =
        DateTime(state.selectedDate!.year, month, state.selectedDate!.day);

    // This can happen for example when the month only has 28 days, but the
    // previous month had 31. Set it to the last day of the new month
    if (newDate.month > month) {
      newDate = DateTime(newDate.year, month + 1, 0);
    }

    emit(state.copyWith(
      selectedDate: newDate,
      days: generateDays(newDate),
    ));
  }
}