flutter_calendar_view icon indicating copy to clipboard operation
flutter_calendar_view copied to clipboard

Next month is wrong when page changes

Open petretiandrea opened this issue 2 years ago • 4 comments

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.

petretiandrea avatar Mar 31 '22 16:03 petretiandrea

The same bug is encountered also in day view.

Step to reproduce:

  1. Show day view
  2. Click on April 2, 2022
  3. Click on March 31, 2022
  4. Swipe to the April 1, 2022
  5. Click on April 2, 2022
  6. Swipe to the April 1, 2022
  7. Now, component does not display view of April 1, 2022

mrdev023 avatar Apr 01 '22 14:04 mrdev023

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.

manueltag avatar Apr 15 '22 11:04 manueltag

I am stuck with this. Has a fixed version been released?

Mind-Reaper avatar May 31 '22 19:05 Mind-Reaper

Hello guys, Is this issue still reproducible in latest release?

PRBaraiya avatar Jun 03 '22 12:06 PRBaraiya

I'm considering this as fixed as there are no response. Please reopen this issue if this issue is still there.

ParthBaraiya avatar Nov 19 '22 16:11 ParthBaraiya