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 replace the view header with the custom widget in Flutter Date Range Picker (SfDateRangePicker)

Platform: Flutter |
Control: SfDateRangePicker |
Published Date: November 18, 2020 |
Last Revised Date: May 7, 2021

In the Flutter date range picker, you can replace the default view header with custom widget by hiding the header, view header in the date range picker.

STEP 1: Inside the state, initialize the default values needed for replacing the view header in calendar.

final List<String> _days = <String>['S', 'M', 'T', 'W', 'T', 'F', 'S'];
final List<Icon> _icons = <Icon>[
  Icon(
    Icons.ac_unit,
    color: Colors.black,
  ),
  Icon(Icons.wb_sunny, color: Colors.amber),
  Icon(
    Icons.wb_incandescent,
    color: Color(0xFF0ba0000),
  ),
  Icon(Icons.wb_auto, color: Colors.orange),
  Icon(Icons.wb_cloudy, color: Colors.grey),
  Icon(Icons.wb_sunny, color: Colors.amber),
  Icon(
    Icons.wb_incandescent,
    color: Color(0xFF0ba0000),
  )
];

STEP 2: Set the headerHeight and viewHeaderHeight property value to 0 to hide the default headers.

child: SfDateRangePicker(
  headerHeight: 0,
  view: DateRangePickerView.month,
  monthViewSettings: DateRangePickerMonthViewSettings(
      viewHeaderHeight: 0,
      showTrailingAndLeadingDates: true),
),

STEP 3: Custom view header implementation using the ListView widgets inside the Stack widget.

child: Stack(
  children: [
    ListView.builder(
        padding: const EdgeInsets.fromLTRB(40, 100, 40, 300),
        itemCount: _days.length,
        scrollDirection: Axis.horizontal,
        itemBuilder: (BuildContext ctxt, int index) {
          return Container(
            padding: const EdgeInsets.only(left: 15, top: 5),
            width: cellWidth,
            height: 5,
            color: Colors.lightGreen,
            child: Text(_days[index]),
          );
        }),
    ListView.builder(
        padding: const EdgeInsets.fromLTRB(40, 120, 40, 500),
        itemCount: _icons.length,
        scrollDirection: Axis.horizontal,
        itemBuilder: (BuildContext ctxt, int index) {
          return Container(
            padding: const EdgeInsets.only(left: 5),
            width: cellWidth,
            child: _icons[index],
          );
        }),
  ],
),

View sample in GitHub

viewheader

 

 

 

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