Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix next month calculation during page changes #56

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions lib/src/extensions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,12 @@ extension DateTimeExtensions on DateTime {
totalMinutes ~/ 60,
totalMinutes % 60,
);

DateTime get lastDayOfMonth {
final beginningNextMonth =
(month < 12) ? DateTime(year, month + 1, 1) : DateTime(year + 1, 1, 1);
return beginningNextMonth.subtract(Duration(days: 1));
}
}

extension ColorExtension on Color {
Expand Down
7 changes: 5 additions & 2 deletions lib/src/month_view/month_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -330,11 +330,14 @@ class MonthViewState<T> extends State<MonthView<T>> {
/// Calls when user changes page using gesture or inbuilt methods.
void _onPageChange(int value) {
if (mounted) {
final newMonth = _currentDate.month + (value - _currentIndex);
final newDay =
DateTime(_currentDate.year, newMonth, 1).lastDayOfMonth.day;
setState(() {
_currentDate = DateTime(
_currentDate.year,
_currentDate.month + (value - _currentIndex),
_currentDate.day,
newMonth,
newDay,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@petretiandrea Can we pass 1 statically here instead of calculating last day?

);
_currentIndex = value;
});
Expand Down