endOfWeek property

DateTime get endOfWeek

Get the end of the week (Sunday)

Example:

final date = DateTime(2023, 12, 25); // Wednesday
print(date.endOfWeek); // Sunday of that week at 23:59:59.999

Implementation

DateTime get endOfWeek {
  final daysToSunday = 7 - weekday;
  return add(Duration(days: daysToSunday)).endOfDay;
}