DateRangePickerController class

An object that used for programmatic date navigation, date and range selection and view switching in SfDateRangePicker.

A DateRangePickerController served for several purposes. It can be used to selected dates and ranges programmatically on SfDateRangePicker by using thecontroller.selectedDate, controller.selectedDates, controller.selectedRange, controller.selectedRanges. It can be used to change the SfDateRangePicker view by using the controller.view property. It can be used to navigate to specific date by using the controller.displayDate property.

Listening to property changes:

The DateRangePickerController is a listenable. It notifies it's listeners whenever any of attached SfDateRangePicker`s selected date, display date and view changed (i.e: selecting a different date, swiping to next/previous view and navigates to different view] in in SfDateRangePicker.

The SfDateRangePicker visible view can be changed by using the Controller.view property, the property allow to change the view of SfDateRangePicker programmatically on initial load and in rum time.

Programmatic selection:

In SfDateRangePicker selecting dates programmatically can be achieved by using the controller.selectedDate, controller.selectedDates, controller.selectedRange, controller.selectedRanges which allows to select the dates or ranges programmatically on SfDateRangePicker on initial load and in run time.

See also: DateRangePickerSelectionMode

Defaults to null.

This example demonstrates how to use the SfDateRangePickerController for SfDateRangePicker.


class MyApp extends StatefulWidget {
 @override
 MyAppState createState() => MyAppState();
}

class MyAppState extends State<MyApp> {
 DateRangePickerController _pickerController;

 @override
 void initState() {
   _pickerController = DateRangePickerController();
   _pickerController.selectedDates = <DateTime>[
     DateTime.now().add(Duration(days: 2)),
     DateTime.now().add(Duration(days: 4)),
     DateTime.now().add(Duration(days: 7)),
     DateTime.now().add(Duration(days: 11))
   ];
   _pickerController.displayDate = DateTime.now();
   _pickerController.addPropertyChangedListener(handlePropertyChange);
   super.initState();
 }

 void handlePropertyChange(String propertyName) {
   if (propertyName == 'selectedDates') {
     final List<DateTime> selectedDates = _pickerController.selectedDates;
   } else if (propertyName == 'displayDate') {
     final DateTime displayDate = _pickerController.displayDate;
   }
 }

 @override
 Widget build(BuildContext context) {
   return MaterialApp(
     home: Scaffold(
       body: SfDateRangePicker(
         view: DateRangePickerView.month,
         controller: _pickerController,
         selectionMode: DateRangePickerSelectionMode.multiple,
       ),
     ),
   );
 }
}

Inheritance

Constructors

DateRangePickerController()

Properties

displayDate DateTime
The first date of the current visible view month, when the MonthViewSettings.numberOfWeeksInView set with default value 6. [...]
read / write
hashCode int
The hash code for this object. [...]
read-only, inherited
runtimeType Type
A representation of the runtime type of the object.
read-only, inherited
selectedDate DateTime
The selected date in the SfDateRangePicker. [...]
read / write
selectedDates List<DateTime>
The list of dates selected in the SfDateRangePicker. [...]
read / write
selectedRange PickerDateRange
selected date range in the SfDateRangePicker. [...]
read / write
selectedRanges List<PickerDateRange>
List of selected ranges in the SfDateRangePicker. [...]
read / write
view DateRangePickerView
The current visible DateRangePickerView of SfDateRangePicker.
read / write

Methods

addPropertyChangedListener(DateRangePickerValueChangedCallback _listener) → void
Calls the listener every time the controller's property changed. [...]
inherited
backward() → void
Moves to the previous view programmatically with animation by checking that the previous view dates falls between the minimum and maximum date range. [...]
dispose() → void
Discards any resources used by the object. After this is called, the object is not in a usable state and should be discarded (calls to addListener and removeListener will throw after the object is disposed). [...]
@mustCallSuper, inherited
forward() → void
Moves to the next view programmatically with animation by checking that the next view dates falls between the minimum and maximum date range. [...]
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed. [...]
inherited
notifyPropertyChangedListeners(String value) → void
Call all the registered listeners. [...]
inherited
removePropertyChangedListener(DateRangePickerValueChangedCallback _listener) → void
remove the listener used for notify the data source changes. [...]
inherited
toString() String
Returns a string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator. [...]
inherited