Articles in this section
Category / Section

How to change the month header format in the Flutter Calendar

4 mins read

In the Flutter Event Calendar, you can customize the month header format using the headerDateFormat property.

Use the onViewChanged callback to dynamically change the header format based on different calendar views.

child: SfCalendar(
  view: CalendarView.day,
  controller: _controller,
  allowedViews: [
    CalendarView.day,
    CalendarView.week,
    CalendarView.workWeek,
    CalendarView.month,
    CalendarView.timelineDay,
    CalendarView.timelineWeek,
    CalendarView.timelineWorkWeek,
    CalendarView.timelineMonth,
    CalendarView.schedule
  ],
  dataSource: _getCalendarDataSource(),
  headerDateFormat: _headerFormat,
  onViewChanged: viewChanged,
)
 
void viewChanged(ViewChangedDetails viewChangedDetails) {
  if (_controller.view == CalendarView.day) {
    _headerFormat = 'yyy MMM';
  } else if (_controller.view == CalendarView.week ||
      _controller.view == CalendarView.workWeek ||
      _controller.view == CalendarView.timelineDay ||
      _controller.view == CalendarView.timelineMonth) {
    _headerFormat = 'MMM yyy';
  } else if (_controller.view == CalendarView.month) {
    _headerFormat = 'MMMM yy';
  } else if (_controller.view == CalendarView.timelineWeek ||
      _controller.view == CalendarView.timelineWorkWeek) {
    _headerFormat = 'MMM yy';
  } else {
    _headerFormat = 'yyy';
  }
  SchedulerBinding.instance!.addPostFrameCallback((timeStamp) {
    setState(() {
 
    });
  });
}

View the GitHub sample here

Change Month Header Format in Flutter Calendar

Conclusion

I hope you enjoyed learning about how to change the month header format in the Flutter Calendar.

You can refer to our  Flutter Calendar feature tour page to know about its other groundbreaking feature representations. You can also explore our Flutter Calendar documentation to understand how to create and manipulate data.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion®, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you!



Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied