Articles in this section
Category / Section

How to programmatically select the date in the Flutter Date Range Picker (SfDateRangePicker)

1 min read

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

 

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments
Please  to leave a comment
Access denied
Access denied