How to format the view header day and date in the Flutter Calendar?
In the Flutter Event Calendar, you can format the view header date and day by using the dayFormat and dateFormat properties in TimeSlotViewSettings.
Inside the state initialize the default values for calendar.
final CalendarController _controller = CalendarController(); String _dayFormat = 'EEE', _dateFormat = 'dd'; CalendarDataSource? _dataSource; @override initState() { _dataSource = _getCalendarDataSource(); super.initState(); }
Using onViewChanged callback get the current calendar view, based on the calendar views, set the dayFormat and dateFormat.
void viewChanged(ViewChangedDetails viewChangedDetails) { if (_controller.view == CalendarView.day) { SchedulerBinding.instance!.addPostFrameCallback((Duration duration) { if (_dayFormat != 'EEEEE' || _dateFormat != 'dd') { setState(() { _dayFormat = 'EEEEE'; _dateFormat = 'dd'; }); } else { return; } }); } else { SchedulerBinding.instance!.addPostFrameCallback((Duration duration) { if (_dayFormat != 'EEE' || _dateFormat != 'dd') { setState(() { _dayFormat = 'EEE'; _dateFormat = 'dd'; }); } else { return; } }); } }
Assign _dayFormat and _dateFormat values to the calendar.
child: SfCalendar( view: CalendarView.week, allowedViews: [ CalendarView.day, CalendarView.week, CalendarView.workWeek ], controller: _controller, dataSource: _dataSource, timeSlotViewSettings: TimeSlotViewSettings( dateFormat: _dateFormat, dayFormat: _dayFormat), onViewChanged: viewChanged, ),
Day view
|
| Week view
| Work week view
|
Conclusion
I hope you enjoyed learning about how to format the view header day and date in the Flutter Calendar.
You can refer to our Flutter Calender 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 forums, Direct-Trac, or feedback portal. We are always happy to assist you!