Articles in this section
Category / Section

How to replace view header with custom widget in Flutter Date Range Picker?

1 min read

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

 

 

 


Conclusion

I hope you enjoyed learning about how to replace the view header with custom widget in the Flutter Date Range Picker.

You can refer to our Flutter Date Range Picker feature tour page to know about its other groundbreaking feature representations documentation and how to quickly get started for configuration specifications.  You can also explore our Flutter Date Range Picker example 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  to leave a comment
Access denied
Access denied