Live Chat Icon For mobile
Live Chat Icon
Popular Categories.NET  (143).NET Core  (23)Angular  (39)ASP.NET  (47)ASP.NET Core  (53)ASP.NET MVC  (83)Azure  (27)Blazor  (49)DocIO  (18)Essential JS 2  (64)Essential Studio  (159)Flutter  (53)JavaScript  (134)Microsoft  (96)PDF  (48)React  (29)Succinctly series  (118)Syncfusion  (400)TypeScript  (30)Uno Platform  (2)UWP  (4)Vue  (25)Webinar  (14)Windows Forms  (52)WPF  (92)Xamarin  (105)XlsIO  (20)Other CategoriesBarcode  (4)BI  (29)Bold BI  (3)Build conference  (6)Business intelligence  (53)Button  (4)C#  (100)Chart  (40)Cloud  (8)Company  (445)Dashboard  (4)Data Science  (3)Data Validation  (2)DataGrid  (31)Development  (234)Doc  (7)eBook  (89)Enterprise  (22)Entity Framework  (5)Essential Tools  (14)Excel  (14)Extensions  (7)File Manager  (3)Gantt  (6)Gauge  (4)Git  (3)Grid  (24)HTML  (8)Installer  (1)Knockout  (2)LINQPad  (1)Linux  (1)M-Commerce  (1)Metro Studio  (11)Mobile  (140)Mobile MVC  (9)OLAP server  (1)Orubase  (12)Partners  (20)PDF viewer  (15)Performance  (2)PHP  (1)PivotGrid  (4)Predictive Analytics  (6)Report Server  (3)Reporting  (10)Reporting / Back Office  (11)Rich Text Editor  (5)Road Map  (9)Scheduler  (15)SfDataGrid  (7)Silverlight  (21)Sneak Peek  (12)Solution Services  (2)Spreadsheet  (2)SQL  (4)Stock Chart  (1)Surface  (4)Tablets  (5)Theme  (9)Tips and Tricks  (17)UI  (62)Uncategorized  (68)Unix  (2)User interface  (49)Visual State Manager  (1)Visual Studio  (12)Visual Studio Code  (7)Web  (99)What's new  (62)Windows 8  (19)Windows App  (1)Windows Phone  (15)Windows Phone 7  (9)WinRT  (26)
Share on twitter
Share on facebook
Share on linkedin
Introducing a Special Time Region in the Flutter Event Calendar

Introducing a Special Time Region in the Flutter Event Calendar

“Time is the scarcest resource and unless it is managed, nothing else can be managed.”

– Peter Drucker

Almost all applications with time regions include features for setting lunch hours, nonworking hours, holidays, and nonworking days, but these features are often not flexible enough to be used for other application-specific use cases. To assist you in managing your valuable time more efficiently, we at Syncfusion have integrated the special time region feature into our Flutter Calendar widget. It allows or restricts user interaction, such as for selection and highlights, in certain time frames. This feature became available in our 2020 Volume 2 release.

Through this feature, you can:

  • Restrict selection in single or multiple time slots.
  • Set unique colors to specific time slots.
Special Time Region In Event Calendar
Special Time Region In Event Calendar

 

In this blog post, I will explain the key features of the special time region in the Calendar widget. If you are new to the Calendar control, please go through the Getting Started article in the Calendar documentation before proceeding.

Let’s get started!

Adding a special time region

You can create a special time region by using the TimeRegion class available in the Calendar widget. In it, you can set the start and end time of the time region. You can also set values to the created time regions collection to the specialTimeRegion property available in the Calendar.

Refer the following code example.

@override
  Widget build(BuildContext context) {
    return Container(
      child: SfCalendar(
         initialDisplayDate: DateTime(2020, 06, 18, 9, 0, 0),
        view: CalendarView.week,
        specialRegions: _getTimeRegions(),
      ),
    );
  }

  List<TimeRegion> _getTimeRegions() {
    final List<TimeRegion> regions = <TimeRegion>[];
    regions.add(TimeRegion(
        startTime: DateTime(2020, 06, 18, 14, 0, 0),
        endTime: DateTime(2020, 06, 18, 15, 0, 0),        
        color: Colors.grey.withOpacity(0.2),
        text: 'Break'));

    return regions;
  }   

After executing the previous code, we will get the following output, in which the time between 2 p.m. and 3 p.m. on 18 June 2020, is labelled Break in the calendar.

Added Break Time
Added Break Time

Restrict user interaction in timeslots

The enablePointerInteraction property specifies whether the user interactions are restricted or not in timeslot cells. So, special time regions can function in both ways:

  • To lock specific time cells to user interaction.
  • To unlock them for user interaction.

Refer to the following code example.

@override
  Widget build(BuildContext context) {
    return Container(
      child: SfCalendar(
         initialDisplayDate: DateTime(2020, 06, 18, 9, 0, 0),
        view: CalendarView.week,
        specialRegions: _getTimeRegions(),
      ),
    );
  }

  List<TimeRegion> _getTimeRegions() {
    final List<TimeRegion> regions = <TimeRegion>[];
regions.add(TimeRegion(
        startTime: DateTime(2020, 06, 18, 14, 0, 0),
        endTime: DateTime(2020, 06, 18, 15, 0, 0),
        color: Colors.grey.withOpacity(0.3),
        text: 'Break'));
    regions.add(TimeRegion(
        startTime: DateTime(2020, 06, 18, 16, 0, 0),
        endTime: DateTime(2020, 06, 18, 17, 0, 0),
        color: Colors.black26,
        enablePointerInteraction: false,
        iconData: Icons.close,
        textStyle: TextStyle(
          color: Colors.red,
          fontSize: 15,
          fontWeight: FontWeight.bold,
        )));
    return regions;
  }

Executing this code will deliver the following output in which user interaction is restricted between 4 p.m. and 5 p.m. (represented by a cross symbol.)

Restricted User Interaction
Restricted User Interaction

Recurring time region

The time region has the same recurrence settings as appointments, the recurring time region being on a daily, weekly, monthly, or yearly interval. You can create recurring special time regions by setting the appropriate recurrence rule in the recurrenceRule property available in the TimeRegion of the Calendar widget.

If you want to learn more about the recurrence rule, refer to our Calendar widget documentation.

Refer to the following code example.

@override
  Widget build(BuildContext context) {
    return Container(
      child: SfCalendar(
         initialDisplayDate: DateTime(2020, 06, 18, 9, 0, 0),
        view: CalendarView.week,
        specialRegions: _getTimeRegions(),
      ),
    );
  }

  List<TimeRegion> _getTimeRegions() {
    final List<TimeRegion> regions = <TimeRegion>[];
regions.add(TimeRegion(
        startTime: DateTime(2020, 06, 14, 14, 0, 0),
        endTime: DateTime(2020, 06, 14, 15, 0, 0),
        color: Colors.grey.withOpacity(0.2),
        recurrenceRule: 'FREQ=WEEKLY;BYDAY=MO,TU,WE,TH,FR;INTERVAL=1',
        textStyle: TextStyle(color: Colors.black45, fontSize: 15),
        text: 'Break'));
    regions.add(TimeRegion(
        startTime: DateTime(2020, 06, 14, 0, 0, 0),
        endTime: DateTime(2020, 06, 14, 24, 0, 0),
        color: Colors.grey.withOpacity(0.2),
        enablePointerInteraction: false,
        recurrenceRule: 'FREQ=WEEKLY;BYDAY=SU,SA;INTERVAL=1',
        ));   
 return regions;
  }

When executing this code, we will get the following output in which the Break time occurs from Monday to Friday, between 2 p.m. and 3 p.m.

Recurring Time Region
Recurring Time Region

Recurrence exception dates

You can delete any of the occurrences that are exceptions to the recurrence pattern time region. This can be done by setting the appropriate dates to the recurrenceExceptionDates property available in the TimeRegion of the Calendar widget. The deleted occurrence date will be considered a recurrence exception date.

Refer to the following code example.

@override
  Widget build(BuildContext context) {
    return Container(
      child: SfCalendar(
         initialDisplayDate: DateTime(2020, 06, 18, 9, 0, 0),
        view: CalendarView.week,
        specialRegions: _getTimeRegions(),
      ),
    );
  }

  List<TimeRegion> _getTimeRegions() {
    final List<TimeRegion> regions = <TimeRegion>[];

regions.add(TimeRegion(
        startTime: DateTime(2020, 06, 14, 14, 0, 0),
        endTime: DateTime(2020, 06, 14, 15, 0, 0),
        color: Colors.grey.withOpacity(0.2),
        recurrenceRule: 'FREQ=WEEKLY;BYDAY=MO,TU,WE,TH,FR;INTERVAL=1',
        recurrenceExceptionDates: [
          DateTime(2020, 06, 16),
          DateTime(2020, 06, 18)
        ],
        textStyle: TextStyle(color: Colors.black45, fontSize: 15),
        text: 'Break'));
    regions.add(TimeRegion(
      startTime: DateTime(2020, 06, 14, 0, 0, 0),
      endTime: DateTime(2020, 06, 14, 24, 0, 0),
      color: Colors.grey.withOpacity(0.2),
      enablePointerInteraction: false,
      recurrenceRule: 'FREQ=WEEKLY;BYDAY=SU,SA;INTERVAL=1',
    ));
    return regions;
  }

Executing this code will result in the following output in which the Break recurrence has been exempted for the 16 and 18 of June 2020.

Recurrence exception dates

View customization

To provide a uniform and consistent look, the special time region feature allows you to customize the color and text style of the time regions.

Customize the background color of the specialTimeRegion by setting an appropriate color to the color property. Customize the text style for the text and icon using textStyle property of the specialTimeRegion.

Refer to the following code example.

@override
  Widget build(BuildContext context) {
    return Container(
      child: SfCalendar(
         initialDisplayDate: DateTime(2020, 06, 18, 9, 0, 0),
        view: CalendarView.week,
        specialRegions: _getTimeRegions(),
      ),
    );
  }

  List<TimeRegion> _getTimeRegions() {
    final List<TimeRegion> regions = <TimeRegion>[];
    regions.add(TimeRegion(
        startTime: DateTime(2020, 06, 18, 14, 0, 0),
        endTime: DateTime(2020, 06, 18, 15, 0, 0),
        enablePointerInteraction: false,
        textStyle: TextStyle(color: Colors.red, fontSize: 15),
        color: Color.fromRGBO(255, 236, 179, 1.0),
        iconData: Icons.group));

    return regions;
  }
Color and Icon Customization

Conclusion

In this blog post, we had a quick overview of the special time region’s key features introduced in the Flutter Calendar. This feature became available in the Essential Studio 2020 Volume 2 release.

Try out these versatile custom features and manage your time efficiently!

You can explore other features in the Calendar widget’s documentation, where you can find detailed explanations of each feature with code examples.

Please feel free to try out the samples available in our GitHub location, and share your feedback or ask questions in the comments section below. You can also contact us through our support forumDirect-Trac, or feedback portal. We are always happy to assist you!

Tags:

Share this post:

Share on twitter
Share on facebook
Share on linkedin

Leave a comment

Popular Now

Be the first to get updates

Subscribe RSS feed
Scroll To Top