Articles in this section
Category / Section

How to highlight the lunch hours in the Flutter Calendar

1 min read

In the Flutter Event Calendar, you can highlight the time slot for lunch hour using the ‘specialRegions’ property of Calendar.

STEP 1: Add the time region for lunch hour using the ‘startTime’, ’endTime’ properties of the `TimeRegion`. Using `recurrenceRule ` property of the time region to repeat the time regions with all the weekdays after the start time date.

List<TimeRegion> _getTimeRegions() {
  final List<TimeRegion> regions = <TimeRegion>[];
  regions.add(TimeRegion(
      startTime: DateTime(2020, 5, 29, 13, 0, 0),
      endTime: DateTime(2020, 5, 29, 14, 0, 0),
      recurrenceRule: 'FREQ=WEEKLY;INTERVAL=1;BYDAY=MON,TUE,WED,THU,FRI',
      text: "Special region",
      color: Color(0xFFBD3D3D3),
      enablePointerInteraction: true,
      textStyle: TextStyle(
        color: Colors.black,
      )));
 
  return regions;
}

STEP 2: Call the _getTimeRegions() method to customize the specified time slot of the SfCalendar. Please find the code snippet for the same.

body: SafeArea(
  child: SfCalendar(
    view: CalendarView.week,
    allowedViews: [
      CalendarView.day,
      CalendarView.week,
      CalendarView.workWeek,
      CalendarView.timelineDay,
      CalendarView.timelineWeek,
      CalendarView.timelineWorkWeek,
    ],
    dataSource: getCalendarDataSource(),
    specialRegions: _getTimeRegions(),
  ),

Highlighted timeslots touch interaction can be enabled or disabled.

Reference blog: https://www.syncfusion.com/blogs/post/introducing-a-special-time-region-in-the-flutter-event-calendar.aspx

View sample in Github

Flutter calendar special region

 

 

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