-
-
Notifications
You must be signed in to change notification settings - Fork 69
Open
Description
Is there an existing issue for this?
- I have searched the existing issues
What happened?
📌 Issue Overview
The TableCalendar widget crashes with a failed assertion error when the focusedDay is outside the range defined by firstDay and lastDay. This issue occurs because the focusedDay is initialized to DateTime.now(), which may not always fall within the hardcoded date range.
🔍 Steps to Reproduce
- Set up a TableCalendar widget with a hardcoded date range, e.g.:
TableCalendar(
firstDay: DateTime.utc(2024, 1, 1),
lastDay: DateTime.utc(2025, 12, 31),
focusedDay: DateTime.now(),
...
)
- Run the app on a date outside the specified range (e.g., DateTime.now() is 2026-01-17).
- Observe the app crash with the following error:
'package:table_calendar/src/table_calendar_base.dart':
Failed assertion: line 78 pos 16:
'isSameDay(focusedDay, lastDay) || focusedDay.isBefore(lastDay)': is not true.
🎯 Expected Behavior
The TableCalendar widget should handle dynamic date ranges and not crash when the focusedDay is outside the range. The widget should either:
- Automatically adjust the focusedDay to the nearest valid date within the range.
- Allow dynamic date ranges to prevent the need for hardcoding.
🚨 Actual Behavior
The app crashes with a failed assertion error when the focusedDay is outside the firstDay and lastDay range.
📷 Screenshot
💡 Suggested Improvements
- Use a dynamic date range for firstDay and lastDay to ensure the calendar always includes the current date
- Add an onPageChanged callback to update the focusedDay dynamically as the user navigates through the calendar.
Record
- I agree to follow this project's Code of Conduct
- I want to work on this issue
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels