getWeekDates function

List<int> getWeekDates()

Retourns the day numbers of the current week, from monday to sunday. Ex: 26, 27, 28, 29, 30, 31, 1.

Implementation

List<int> getWeekDates() {
  final List<int> dates = [];
  DateTime temp = DateTime.now();

  final int todayDate = temp.day;
  dates.add(todayDate);

  final int todayIndex = getDayIndex(getToday());

  for (int i = 0; i < todayIndex; i++) {
    temp = temp.subtract(const Duration(hours: 24));
    dates.insert(0, temp.day);
  }

  temp = DateTime.now();
  for (int i = todayIndex + 1; i < 7; i++) {
    temp = temp.add(const Duration(hours: 24));
    dates.add(temp.day);
  }

  return dates;
}