table_calendar
table_calendar copied to clipboard
setState needed onPageChanged
I just upgraded to 3.x.x supporting null safety.
I have a scheduling app that lists weekly shifts for employees based on the current week displayed by Table Calendar. Scrolling from week to week updates the UI to display all the shifts scheduled in that weekly timeframe.
In order to make this work, I need to get the beginning and end days of the week, and run a FutureBuilder to get all shifts being worked in that time, and display them below the Calendar widget.
In previous versions, this worked fine because you could call setState inside of onVisibleDaysChanged without any problems with the UI of the calendar.
The docs for this version clearly state you should not use setState inside of onPageChanged, which is the callback that replaced onVisibleDaysChanged. However, I need to rebuild the tree in order to re-call the API using the new beginning and end dates of the week calculated by the updated focusedDay provided by the callback.
If you try to use setState inside of the onPageChanged callback, the focusedDay holds onto its value and the API calls and updates correctly, however the UI of the calendar skips a week forward or backwards. I have only tested this in the single-week view, as this is all I use.
Is there a workaround for still needing to use setState in these callbacks?
I came to a work around, give the focusDay same value returning from onPageChanged dateTime
i came across same issue, i need to fetch the some data whenever the page changed. the workaround is to use ValueNotifier