week property
Returns the start and end dates of the current week.
The week starts on Monday and ends on Sunday.
Example:
final range = DateTime.now().week;
final start = range.first;
final end = range.last;
Implementation
List<DateTime> get week {
final currentDay = DateTime(year, month, day);
// Monday as the first day of the week
final beginDay = weekday - 1;
final begin = currentDay.subtract(Duration(days: beginDay));
// Sunday as the last day of the week
final endDay = 7 - weekday;
final end = currentDay.add(Duration(days: endDay));
return [begin, end];
}