flutter_calendar_view
flutter_calendar_view copied to clipboard
Next month is wrong when page changes
Months with 31 days are buggy when pages change. For example, today: 31 March 2022, when I change the month page (in MonthView) the view jumps to 2022 May.
To reproduce the bug, you can simply use a mobile phone and change the current system date to 31 March (or any other months with 31 days) and try to swipe to change page.
The same bug is encountered also in day view.
Step to reproduce:
- Show day view
- Click on April 2, 2022
- Click on March 31, 2022
- Swipe to the April 1, 2022
- Click on April 2, 2022
- Swipe to the April 1, 2022
- Now, component does not display view of April 1, 2022
Hi, I think the problem in day view is in getDayDifference function. This is an example:
void main() {
DateTime epochDate = DateTime(1970);
print(getDayDifference(epochDate, DateTime(2022, 4, 15))); // 19096
print(getDayDifference(epochDate, DateTime(2022, 4, 15, 1))); // 19097
}
int getDayDifference(DateTime date1, DateTime date2) => date1.difference(date2).inDays.abs();
The function is used in initState of the day_view.dart component:
_totalDays = _maxDate.getDayDifference(_minDate) + 1;
_currentIndex = _currentDate.getDayDifference(_minDate);
And when you jump between the days.
When initializing _initialDay without widget.initialDay, the value is DateTime.now() (based on current locale).
I think all the calculations to get the difference of the days have to be done in UTC format.
I am stuck with this. Has a fixed version been released?
Hello guys, Is this issue still reproducible in latest release?
I'm considering this as fixed as there are no response. Please reopen this issue if this issue is still there.