We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to customize the month cell of the Flutter date range picker (SfDateRangePicker)?

Platform: Flutter |
Control: SfDateRangePicker |
Published Date: April 1, 2020 |
Last Revised Date: November 20, 2020

In the Flutter date range picker, you can customize the month cells by using the `specialDates`, `blackoutDates`, and `showTrailingAndLeadingDates` properties.

Step 1:

In initState(), set the default dates for special, blackout dates, and set the default color values for the weekend days, special dates, current date, blackout dates, leading and trailing dates.

DateRangePickerController _controller;
List<DateTime> _blackoutDates;
List<DateTime> _specialDates;
Color weekEndColor,
    specialDatesColor,
    todayColor,
    leadingTrailingDatesColor,
    blackoutDatesColor;
 
@override
void initState() {
  // TODO: implement initState
  _controller = DateRangePickerController();
  _blackoutDates = _getBlackoutDates();
  _specialDates = _getSpecialDates();
  weekEndColor = Color(0xFF0e9aa7);
  leadingTrailingDatesColor = Color(0xFF88d8b0);
  specialDatesColor = Color(0xFFf6cd61);
  todayColor = Color(0xFFff6f69);
  blackoutDatesColor = Colors.black;
  super.initState();
}

 

Step 2:

Place the calendar inside the body of the Scaffold widget. Using the `TextStyle` and `BoxDecoration` widget you can customize the dates with shapes and colors. In the same way, you can also customize the blackout dates.

body: Card(
  margin: const EdgeInsets.fromLTRB(40, 150, 40, 150),
  child: SfDateRangePicker(
    view: DateRangePickerView.month,
    monthViewSettings: DateRangePickerMonthViewSettings(
        specialDates: _specialDates,
        showTrailingAndLeadingDates: true,
        blackoutDates: _blackoutDates),
    monthCellStyle: DateRangePickerMonthCellStyle(
        blackoutDateTextStyle: TextStyle(
            color: blackoutDatesColor,
            decoration: TextDecoration.lineThrough),
        specialDatesDecoration: BoxDecoration(
            shape: BoxShape.circle,
            border: Border.all(width: 1),
            color: specialDatesColor),
        specialDatesTextStyle: TextStyle(color: Colors.black),
        cellDecoration: BoxDecoration(shape: BoxShape.circle),
        selectionColor: Color(0xFFf8dbdff),
        todayTextStyle: TextStyle(color: Colors.white),
        todayCellDecoration:
            BoxDecoration(shape: BoxShape.circle, color: todayColor),
        weekendDatesDecoration: BoxDecoration(
            color: weekEndColor,
            border: Border.all(width: 1),
            shape: BoxShape.circle),
        trailingDatesDecoration: BoxDecoration(
            shape: BoxShape.rectangle, color: leadingTrailingDatesColor),
        leadingDatesDecoration: BoxDecoration(
            shape: BoxShape.rectangle, color: leadingTrailingDatesColor)),
    todayHighlightColor: Colors.orange,
  ),
));

 

View sample in Github.

Screenshot:

 

cell customization

 

 

 

 

 

 

ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon