Articles in this section
Category / Section

How to get the selected date from the Flutter Date Range Picker (SfDateRangePicker)

3 mins read

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

 

View sample in Github.

Screenshots:

 

Selected date

 

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 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 sign in to leave a comment
Access denied
Access denied