Articles in this section
Category / Section

Range selection using the multiple view picker in the Flutter Date Range Picker.

4 mins read

In the Flutter Date Range Picker, you can select the dates ranges from different pickers.

picker with selected ranges

Step 1:

In initState(), set the default values for the date range picker.

@override
void initState() {
  _dateRangePickerController = DateRangePickerController();
  _dateRangePickerController2 = DateRangePickerController();
  rangeStart = '';
  rangeEnd = '';
  super.initState();
}

 

Step 2:

Using the `onPressed` callback of the buttons, show the `AlertDialog` window and place the pickers inside the alert window. Set the `initialDisplayDate` for second picker.

child: FlatButton(
  padding: const EdgeInsets.only(
      left: 20, top: 10, right: 20, bottom: 10),
  child: (rangeStart.isEmpty)
      ? const Text('Start Range')
      : Text(
          rangeStart,
        ),
  onPressed: () {
    showDialog(
        context: context,
        builder: (BuildContext context) {
          return AlertDialog(
              content: Container(
                  height: 300,
                  child: Column(children: <Widget>[
                    Row(
                      mainAxisAlignment:
                          MainAxisAlignment.spaceEvenly,
                      children: <Widget>[
                        getDateRangePicker(
                            _dateRangePickerController,
                            null),
                        getDateRangePicker(
                            _dateRangePickerController2,
                            DateTime(date.year,
                                date.month + 1, date.day)),
                      ],
                    ),
                    ButtonBarTheme(
                        child: ButtonBar(
                      children: <Widget>[
                        FlatButton(
                          child: Text(
                            'Cancel',
                            textAlign: TextAlign.right,
                          ),
                          onPressed: () {
                            Navigator.pop(context, null);
                          },
                        ),
                        FlatButton(
                          child: Text(
                            'Ok',
                            textAlign: TextAlign.right,
                          ),
                          onPressed: () {
                            Navigator.pop(context);
                            setState(() {});
                          },
                        ),
                      ],
                    )),
                  ])));
        });
  },
)),

 

Step 3:

Implement the Flutter calendar `onSelectionChanged` callback to get the selected ranges of the picker and using the `onPressed` event of the button, update selected ranges to button texts using the `DateRangePickerController` selectedRange property.

 

void selectionChanged(DateRangePickerSelectionChangedArgs args) {
  if (args.value is PickerDateRange) {
    rangeStart = DateFormat('dd MMMM, yyyy').format(args.value.startDate);
    rangeEnd = args.value.endDate == null
        ? rangeStart
        : DateFormat('dd MMMM, yyyy').format(args.value.endDate);
    _dateRangePickerController2.selectedRange =
        PickerDateRange(args.value.startDate, args.value.endDate);
    _dateRangePickerController.selectedRange =
        PickerDateRange(args.value.startDate, args.value.endDate);
  }
  SchedulerBinding.instance.addPostFrameCallback((duration) {
  });
}

 

View sample in Github.

Screenshots:

Button texts

picker with selected ranges

selected ranges

Conclusion

I hope you enjoyed learning about how to show two pickers vertically in the Flutter Date Range Picker.

You can refer to our Flutter Date Range Picker feature tour page to know about its other groundbreaking feature representations documentation and how to quickly get started for configuration specifications.  You can also explore our Flutter Date Range Picker example 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