firstDayOfWeek method

DateTime firstDayOfWeek({
  1. bool startWeekOnMonday = true,
})

Return first day of the week

startWeekOnMonday - if true, first day of the week is Monday, otherwise Sunday

lastDayOfWeek - if true, last day of the week is Sunday, otherwise Saturday

Implementation

DateTime firstDayOfWeek({bool startWeekOnMonday = true}) {
  var firstDay = DateTime(year, month, day);
  while (firstDay.weekday != (startWeekOnMonday ? 1 : 7)) {
    firstDay = firstDay.subtract(const Duration(days: 1));
  }
  return firstDay;
}