Articles in this section

How to customize leading and trailing dates using cell builder in the Flutter Date Range Picker (SfDateRangePicker)

In the Flutter date range picker, you can customize the appearance of leading and trailing dates by using the cellBuilder property of the SfDateRangePicker.

Find out the middle date month. If the details (month) of the DateRangePickerCellDetails is not equal to the middle date month, then consider a different text style for that month.

child: SfDateRangePicker(
  monthViewSettings: DateRangePickerMonthViewSettings(
      showTrailingAndLeadingDates: true),
  cellBuilder:
      (BuildContext context, DateRangePickerCellDetails details) {
    int middleDateMonth = details
        .visibleDates[details.visibleDates.length ~/ 2].month;
    if (details.date.month != middleDateMonth) {
      return Center(
        child: Container(
            child: Text(
          DateFormat('d').format(details.date),
          style: TextStyle(color: Colors.grey),
        )),
      );
    } else {
      return Center(
        child: Container(
            child: Text(DateFormat('d').format(details.date))),
      );
    }
  })

View the Github Sample here.


Flutter DateRangePicker leadtrail date customization

 

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Access denied
Access denied