Skip to content

Commit

Permalink
Merge pull request #33 from eugenedina/issue-32
Browse files Browse the repository at this point in the history
Issue 32 - Shifted day when viewing expanded month and start day is Monday.
  • Loading branch information
rwbr authored Mar 24, 2022
2 parents 136bc27 + 836d847 commit 47154ab
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions lib/flutter_neat_and_clean_calendar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -949,7 +949,8 @@ class _CalendarState extends State<Calendar> {
List<DateTime> _daysInMonth(DateTime month) {
var first = Utils.firstDayOfMonth(month);
var daysBefore = first.weekday;
var firstToDisplay = first.subtract(new Duration(days: daysBefore - 1));
var firstToDisplay = first.subtract(
new Duration(days: daysBefore - (widget.startOnMonday ? 1 : 0)));
var last = Utils.lastDayOfMonth(month);

var daysAfter = 7 - last.weekday;
Expand All @@ -959,9 +960,10 @@ class _CalendarState extends State<Calendar> {
daysAfter = 7;
}

// Adding an extra day necessary. Otherwise the week with days in next month
// would always end on Saturdays.
var lastToDisplay = last.add(new Duration(days: daysAfter + 1));
// Adding an extra day necessary (if week starts on Monday).
// Otherwise the week with days in next month would always end on Saturdays.
var lastToDisplay = last.add(
new Duration(days: daysAfter + (widget.startOnMonday ? 1 : 0)));
return Utils.daysInRange(firstToDisplay, lastToDisplay).toList();
}
}
Expand Down

0 comments on commit 47154ab

Please sign in to comment.