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 get the selected date from the Flutter Date Range Picker (SfDateRangePicker)

Platform: Flutter |
Control: SfDateRangePicker |
Published Date: April 15, 2020 |
Last Revised Date: April 22, 2021

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

 

 

 

ADD COMMENT
You must log in to leave a comment

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