daysInMonthGrid static method

List<DateTime> daysInMonthGrid(
  1. DateTime month, {
  2. int firstDayOfWeek = 1,
})

Returns 42 dates (6 weeks) for a month grid view, including leading and trailing days from adjacent months to fill the grid.

Implementation

static List<DateTime> daysInMonthGrid(
  DateTime month, {
  int firstDayOfWeek = 1,
}) {
  final first = firstDayOfMonth(month);
  final startOffset = (first.weekday - firstDayOfWeek + 7) % 7;
  final gridStart = first.subtract(Duration(days: startOffset));

  final days = <DateTime>[];
  for (int i = 0; i < 42; i++) {
    days.add(gridStart.add(Duration(days: i)));
  }
  return days;
}