-
Notifications
You must be signed in to change notification settings - Fork 1k
Description
Describe the bug
When using the TableCalendar within the context of a list view, the TableCalendar keeps its last viewed month and renders it after disposal and rebuild, although I pass the current day (now) as the focused day into the widget at rebuild.
I open a data entry in my list view, where the calendar gets displayed. I switch the month from the current to 2 months forward. I open another data entry and the calendar shows in the top bar the current month, but the displayed month it the one I last saw in my previous entry (2 months forward). When I now go forward, i am 3 months forward from the initial month that should have been displayed.
To reproduce
Please include a short code sample that can be used to reproduce the problem.
class _MyCustomWidgetState extends ConsumerState<CustomCalendar> {
...
void initState() {
super.initState();
_focusedDay = normalizeDate(DateTime.now());
}
...
Widget build(BuildContext context) {
...
return TableCalendar<double>(
key: Key(widget.rid + widget.bid),
focusedDay: _focusedDay,
...
}
Steps to reproduce the behavior:
- Open a data entry in a list view that opens a widget containing the calendar
- Go two months forward in the calendar widget
- Switch the data entry so that the calendar gets rebuilt
- See that the widget is displaying the current month in the top bar, but rendering the days of the month that was last displayed in the first data entry.
Expected behavior
The focusedDay should be always used when building the TableCalendar from the ground up.
When reopening the calendar, it should display the focused day and not magically save the last viewed month.
Screenshots
If applicable, add screenshots to help explain your problem.
Output of flutter doctor
Paste the result of this command here.
[√] Flutter (Channel stable, 3.27.3, on Microsoft Windows [Version 10.0.26100.4652], locale de-DE) [√] Windows Version (Installed version of Windows is version 10 or higher) [√] Android toolchain - develop for Android devices (Android SDK version 35.0.0) [√] Chrome - develop for the web [X] Visual Studio - develop Windows apps X Visual Studio not installed; this is necessary to develop Windows apps. Download at https://visualstudio.microsoft.com/downloads/. Please install the "Desktop development with C++" workload, including all of its default components [√] Android Studio (version 2023.1) [√] VS Code (version unknown) X Unable to determine VS Code version. [√] Connected device (3 available) [√] Network resources
Additional context
The error is due to the page controller used in table_calendar_base.dart (L.105) having the default parameter value keepPage = true. This should be changed to false.