Skip to content

Sasikumar3595/switching-views-date-range-picker-flutter

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

How to switch between the date range picker views in Flutter date range picker (SfDateRangePicker)?

In the flutter date range picker, you can navigate between the picker views. Switching between picker views has been achieved using the view property of DateRangePickerController and tapping the header of the picker views.

Step 1:

In initState(), initialize the controller for date range picker.

DateRangePickerController _controller;
 
@override
void initState() {
  // TODO: implement initState
  _controller = DateRangePickerController();
  super.initState();
}

Step 2:

Navigate between the picker views using the PopupMenuButton widget as follows. Also navigating between the picker views can be achieved by tapping the header of the picker views.

leading: PopupMenuButton<String>(
  icon: Icon(Icons.calendar_today),
  itemBuilder: (BuildContext context) => views.map((String choice) {
    return PopupMenuItem<String>(
      value: choice,
      child: Text(choice),
    );
  }).toList(),
  onSelected: (String value) {
    if (value == 'Month') {
      _controller.view = DateRangePickerView.month;
    } else if (value == 'Year') {
      _controller.view = DateRangePickerView.year;
    } else if (value == 'Decade') {
      _controller.view = DateRangePickerView.decade;
    } else if (value == 'Century') {
      _controller.view = DateRangePickerView.century;
    }
  },
),

Step 3:

Place the calendar inside the body of the Scaffold widget.

body: Card(
  margin: const EdgeInsets.fromLTRB(50, 150, 50, 150),
  child: SfDateRangePicker(
    controller: _controller,
    view: DateRangePickerView.month,
  ),
)

View document in Syncfusion Flutter Knowledge base

Screenshots

month| year| decade| century|

About

How to switch between the calendar views in Flutter date range picker?

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Dart 78.6%
  • Kotlin 10.5%
  • Swift 10.0%
  • Objective-C 0.9%