getAllDaysInBetweenYears static method

List<DateTime> getAllDaysInBetweenYears({
  1. required DateTime startDate,
  2. required DateTime endDate,
})

this function return all the dates in a year from startDate - endDate if endDate = DateTime(2021,3,3) this function will return dates till endDate as DateTime(2022).subtract(Duration

Implementation

static List<DateTime> getAllDaysInBetweenYears({
  required DateTime startDate,
  required DateTime endDate,
}) {
  startDate = DateTime(startDate.year);

  endDate = DateTime(endDate.year + 1);

  List<DateTime> days = [];
  for (var i = 0; i <= (endDate.difference(startDate).inDays) - 1; i++) {
    days.add(DateTime(
      startDate.year,
      startDate.month,
      // In Dart you can set more than. 30 days, DateTime will do the trick
      startDate.day + i,
    ));
  }
  return days;
}