range static method

List<DateTime> range({
  1. required DateTime start,
  2. required DateTime end,
  3. Duration difference = const Duration(days: 1),
})

Implementation

static List<DateTime> range({
  required DateTime start,
  required DateTime end,
  Duration difference = const Duration(days: 1),
}) {
  if (start.isAfter(end)) {
    throw ArgumentError(
      'Initial date must be before or equal to the end date',
    );
  }

  List<DateTime> dates = [];
  DateTime currentDate = start;

  while (!currentDate.isAfter(end)) {
    dates.add(currentDate);
    currentDate = currentDate.add(difference);
  }

  return dates;
}