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; }); }