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 programmatically select the date in the Flutter Date Range Picker (SfDateRangePicker)

Platform: Flutter |
Control: SfDateRangePicker |
Published Date: November 27, 2020 |
Last Revised Date: April 7, 2021

In the Flutter date range picker, you can programmatically select the date using selectedDate property of the DateRangePickerController.

In initState(), initialize the calendar controller.

final DateRangePickerController _controller = DateRangePickerController();

Using onViewChanged callback of the Flutter date picker, you can set the first date of visible dates as selected date. Please find the code snippet.

child: SfDateRangePicker(
  view: DateRangePickerView.month,
  controller: _controller,
  onViewChanged: viewChanged,
),
void viewChanged(DateRangePickerViewChangedArgs args) {
  SchedulerBinding.instance!.addPostFrameCallback((Duration duration) {
    _controller.selectedDate = args.visibleDateRange.startDate;
  });
}

View sample in GitHub

selected date gif

 

ADD COMMENT
You must log in to leave a comment
Comments
James
Dec 31, 2020

This no longer works properly when handling cell rendering via a builder. Any suggestions?

Reply
James
Dec 31, 2020

Nevermind :) THis works fine.

Indumathi Ravichandran [Syncfusion]
Jan 04, 2021

Hi James,

Thank you for contacting Syncfusion support.

Based on the last update, we hope that issue has been resolved at your end. Please get in touch with us if you would require any further assistance.

Regards, Indumathi R

Reply

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