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. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to style a header in the Flutter Date Range Picker (SfDateRangePicker)


In the Flutter Date Range Picker, you can style the header by using headerStyle property in the onViewChanged callback of the date range picker.

In onViewChanged callback, style the date range picker header by using DateRangePickerHeaderStyle properties.

void viewChanged(DateRangePickerViewChangedArgs viewChangedDetails) {
  final DateTime startDate = viewChangedDetails.visibleDateRange.startDate!;
  final DateTime endDate = viewChangedDetails.visibleDateRange.endDate!;
  final int count = endDate.difference(startDate).inDays;
  final DateTime midDate = startDate.add(Duration(days: count ~/ 2));
  SchedulerBinding.instance!.addPostFrameCallback((duration) {
    setState(() {
      if (midDate.month % 2 == 0) {
        _headerStyle = DateRangePickerHeaderStyle(
            textAlign: TextAlign.center,
            backgroundColor: Colors.lightGreen,
            textStyle: TextStyle(
                fontSize: 25,
                fontStyle: FontStyle.normal,
                letterSpacing: 5,
                color: Colors.red,
                fontWeight: FontWeight.w500));
      } else {
        _headerStyle = DateRangePickerHeaderStyle(
            textAlign: TextAlign.center,
            backgroundColor: Colors.purple,
            textStyle: TextStyle(
                fontSize: 25,
                fontStyle: FontStyle.normal,
                letterSpacing: 5,
                color: Colors.orange,
                fontWeight: FontWeight.w500));
      }
    });
  });
}

Assign _headerStyle to the headerStyle property of the date range picker.

child: SfDateRangePicker(
  headerStyle: _headerStyle,
  onViewChanged: viewChanged,
),

View sample in GitHub

headerstylegif

 

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