Articles in this section
Category / Section

How to customize the month cell of the Flutter Date Range Picker (SfDateRangePicker)?

3 mins read

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

Step 1:

Inside the state, set the default color values for the weekend days, special dates, current date, blackout dates, leading and trailing datesand initialize the special and blackout dates on initState().

late List<DateTime> _blackoutDates;
late List<DateTime> _specialDates;
final Color weekEndColor = Color(0xFF0e9aa7),    specialDatesColor = Color(0xFFf6cd61),    todayColor = Color(0xFFff6f69),    leadingTrailingDatesColor = Color(0xFF88d8b0),    blackoutDatesColor = Colors.black;
@overridevoid initState() {
  _blackoutDates = _getBlackoutDates();
  _specialDates = _getSpecialDates();
  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),
    selectionColor: Color(0xFFf8dbdff),
    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),
        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

 

 

 

 

 

 


Conclusion

I hope you enjoyed learning about how to customize the month cell of the Flutter Date Range Picker (SfDateRangePicker).

You can refer to our Flutter DataRangePicker feature tour page to know about its other groundbreaking feature representations. You can also explore our Flutter DateRangePicker 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 sign in to leave a comment
Access denied
Access denied