|
1 | | -# month-cell-customization-date-range-picker-flutter |
2 | | -How to customize the month cells in Flutter date range picker (SfDateRangePicker)? |
| 1 | +# How to customize the month cell of the Flutter date range picker (SfDateRangePicker)? |
| 2 | + |
| 3 | +In the flutter date range picker, you can customize the month cells by using the `specialDates`, `blackoutDates`, and `showTrailingAndLeadingDates` properties. |
| 4 | + |
| 5 | +## Step 1: |
| 6 | +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. |
| 7 | + |
| 8 | +```xml |
| 9 | +DateRangePickerController _controller; |
| 10 | +List<DateTime> _blackoutDates; |
| 11 | +List<DateTime> _specialDates; |
| 12 | +Color weekEndColor, |
| 13 | + specialDatesColor, |
| 14 | + todayColor, |
| 15 | + leadingTrailingDatesColor, |
| 16 | + blackoutDatesColor; |
| 17 | + |
| 18 | +@override |
| 19 | +void initState() { |
| 20 | + // TODO: implement initState |
| 21 | + _controller = DateRangePickerController(); |
| 22 | + _blackoutDates = _getBlackoutDates(); |
| 23 | + _specialDates = _getSpecialDates(); |
| 24 | + weekEndColor = Color(0xFF0e9aa7); |
| 25 | + leadingTrailingDatesColor = Color(0xFF88d8b0); |
| 26 | + specialDatesColor = Color(0xFFf6cd61); |
| 27 | + todayColor = Color(0xFFff6f69); |
| 28 | + blackoutDatesColor = Colors.black; |
| 29 | + super.initState(); |
| 30 | +} |
| 31 | +``` |
| 32 | + |
| 33 | + |
| 34 | +## Step 2: |
| 35 | +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. |
| 36 | + |
| 37 | +```xml |
| 38 | +body: Card( |
| 39 | + margin: const EdgeInsets.fromLTRB(40, 150, 40, 150), |
| 40 | + child: SfDateRangePicker( |
| 41 | + view: DateRangePickerView.month, |
| 42 | + monthViewSettings: DateRangePickerMonthViewSettings( |
| 43 | + specialDates: _specialDates, |
| 44 | + showTrailingAndLeadingDates: true, |
| 45 | + blackoutDates: _blackoutDates), |
| 46 | + monthCellStyle: DateRangePickerMonthCellStyle( |
| 47 | + blackoutDateTextStyle: TextStyle( |
| 48 | + color: blackoutDatesColor, |
| 49 | + decoration: TextDecoration.lineThrough), |
| 50 | + specialDatesDecoration: BoxDecoration( |
| 51 | + shape: BoxShape.circle, |
| 52 | + border: Border.all(width: 1), |
| 53 | + color: specialDatesColor), |
| 54 | + specialDatesTextStyle: TextStyle(color: Colors.black), |
| 55 | + cellDecoration: BoxDecoration(shape: BoxShape.circle), |
| 56 | + selectionColor: Color(0xFFf8dbdff), |
| 57 | + todayTextStyle: TextStyle(color: Colors.white), |
| 58 | + todayCellDecoration: |
| 59 | + BoxDecoration(shape: BoxShape.circle, color: todayColor), |
| 60 | + weekendDatesDecoration: BoxDecoration( |
| 61 | + color: weekEndColor, |
| 62 | + border: Border.all(width: 1), |
| 63 | + shape: BoxShape.circle), |
| 64 | + trailingDatesDecoration: BoxDecoration( |
| 65 | + shape: BoxShape.rectangle, color: leadingTrailingDatesColor), |
| 66 | + leadingDatesDecoration: BoxDecoration( |
| 67 | + shape: BoxShape.rectangle, color: leadingTrailingDatesColor)), |
| 68 | + todayHighlightColor: Colors.orange, |
| 69 | + ), |
| 70 | +)); |
| 71 | +``` |
0 commit comments