How to Get the Selected Date From the Flutter SfDateRangePicker?
In the Flutter Date Range Picker, you can get the selected date of the date range picker using the `onSelectionChanged` callback.
Step 1:
Inside the state, set the default values for the selected date.
final DateRangePickerController _controller = DateRangePickerController(); String _date = DateFormat('dd, MMMM yyyy').format(DateTime.now()).toString();
Step 2:
Implement the 'onSelectionChanged' callback of the flutter date range picker, to get the selected date.
body: Column( children: <Widget>[ Container(height:50, child: Text('SelectedDate:''$_date')), Card( margin: const EdgeInsets.fromLTRB(50, 50, 50, 100), child: SfDateRangePicker( view: DateRangePickerView.month, initialSelectedDate: DateTime.now(), controller: _controller, onSelectionChanged: selectionChanged, ), ) ], ),
Step 3:
Using the `selectionChanged` event, you can get the selected date of the picker.
void selectionChanged(DateRangePickerSelectionChangedArgs args) { SchedulerBinding.instance!.addPostFrameCallback((duration) { setState(() { _date=DateFormat('dd, MMMM yyyy').format(args.value).toString(); }); }); }
Screenshots:
|
|
Conclusion
I hope you enjoyed learning about how to get the selected date from the Flutter Date Range Picker (SfDateRangePicker).
You can refer to our Flutter Date Range Picker feature tour page to know about its other groundbreaking feature representations. You can also explore our documentation 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 forums, Direct-Trac, or feedback portal. We are always happy to assist you!