FadyFayezYounan / easy_date_timeline

The "easy_date_timeline" package is a customizable Flutter widget that displays a timeline of dates in a horizontal timeline.
MIT License
96 stars 46 forks source link

Fix date Rollover Bug in itemBuilder #11

Closed Mustafa7Ibrahim closed 1 year ago

Mustafa7Ibrahim commented 1 year ago

I've encountered a bug in my Flutter code that's causing unexpected behavior when generating a list of dates in an itemBuilder. When the day reaches the end of the month, the code incorrectly rolls over to the next month. Below is the relevant code:

itemBuilder: (context, index) {
    final currentDate = DateTime(initialDate.year, initialDate.month, 1)
        .add(Duration(days: index));
    log(index.toString(), name: "this is index");
    log(currentDate.toString(), name: "this is date");
}

For example, when the index reaches 25, it should create a date for October 25th, but it's actually creating a date for November 1st.

I've realized that the issue occurs because the code doesn't account for the last day of the month. It should stop at the last day of the current month and not go beyond that.

I Updated the code to handle the last day of the month.

FadyFayezYounan commented 1 year ago

Thank you for your feedback. The issue has been resolved, but in a different way. You can take a look at the solution, and I would be happy to hear your opinion.

Mustafa7Ibrahim commented 1 year ago

thank you for fixing the big i can confirm that it fixed now.