RangeController class

Coordinates between SfRangeSelector and the widget which listens to it.

Built-in support for selection and zooming with SfChart.

Range controller contains start and end values.

start - represents the currently selected start value of a range selector. The start thumb of the range selector was drawn corresponding to this value.

end - represents the currently selected end value of the range selector. The end thumb of the range selector was drawn corresponding to this value.

start and end can be either double or DateTime.

Selection in SfChart.

class RangeSelectorPage extends StatefulWidget {
  const RangeSelectorPage({ Key key }) : super(key: key);
  @override
  _RangeSelectorPageState createState() => _RangeSelectorPageState();
}

class _RangeSelectorPageState extends State<RangeSelectorPage>
    with SingleTickerProviderStateMixin {
 final double _min = 2.0;
 final double _max = 10.0;
 RangeController _rangeController;

@override
void initState() {
  super.initState();
    _rangeController = RangeController(
    vsync: this,
    start: _values.start,
    end: _values.end);
}

@override
void dispose() {
  _rangeController.dispose();
  super.dispose();
}

final List<Data> chartData = <Data>[
   Data(x:2.0, y: 2.2),
   Data(x:3.0, y: 3.4),
   Data(x:4.0, y: 2.8),
   Data(x:5.0, y: 1.6),
   Data(x:6.0, y: 2.3),
   Data(x:7.0, y: 2.5),
   Data(x:8.0, y: 2.9),
   Data(x:9.0, y: 3.8),
   Data(x:10.0, y: 3.7),
];

@override
Widget build(BuildContext context) {
 return MaterialApp(
     home: Scaffold(
         body: Center(
             child: SfRangeSelector(
                   min: _min,
                   max: _max,
                   interval: 1,
                   showTicks: true,
                   showLabels: true,
                  controller: _rangeController,
                   child: Container(
                   height: 130,
                  child: SfCartesianChart(
                       margin: const EdgeInsets.all(0),
                       primaryXAxis: NumericAxis(minimum: _min,
                           maximum: _max,
                           isVisible: false),
                       primaryYAxis: NumericAxis(isVisible: false),
                       plotAreaBorderWidth: 0,
                       series: <SplineAreaSeries<Data, double>>[
                           SplineAreaSeries<Data, double>(
                               selectionSettings: SelectionSettings(
                                   enable: true,
                                   selectionController: _rangeController),
                              color: Color.fromARGB(255, 126, 184, 253),
                               dataSource: chartData,
                                   xValueMapper: (Data sales, _) => sales.x,
                                   yValueMapper: (Data sales, _) => sales.y)
                            ],
                        ),
                    ),
                ),
            )
        )
    );
  }
}

Zooming in SfChart.

class RangeZoomingPage extends StatefulWidget {
  const RangeZoomingPage({ Key key }) : super(key: key);
  @override
  _RangeZoomingPageState createState() => _RangeZoomingPageState();
}

class _RangeZoomingPageState extends State<RangeZoomingPage>
    with SingleTickerProviderStateMixin {
 final double _min = 2.0;
 final double _max = 10.0;
 RangeController _rangeController;

@override
void initState() {
  super.initState();
    _rangeController = RangeController(
    vsync: this,
    start: _values.start,
    end: _values.end);
}

@override
void dispose() {
  _rangeController.dispose();
  super.dispose();
}

final List<Data> chartData = <Data>[
   Data(x:2.0, y: 2.2),
   Data(x:3.0, y: 3.4),
   Data(x:4.0, y: 2.8),
   Data(x:5.0, y: 1.6),
   Data(x:6.0, y: 2.3),
   Data(x:7.0, y: 2.5),
   Data(x:8.0, y: 2.9),
   Data(x:9.0, y: 3.8),
   Data(x:10.0, y: 3.7),
];

@override
Widget build(BuildContext context) {
 return MaterialApp(
     home: Scaffold(
         body: Center(
             child: SfRangeSelector(
                   min: _min,
                   max: _max,
                   interval: 1,
                   showTicks: true,
                   showLabels: true,
                  controller: _rangeController,
                   child: Container(
                   height: 130,
                  child: SfCartesianChart(
                       margin: const EdgeInsets.all(0),
                       primaryXAxis: NumericAxis(minimum: _min,
                           maximum: _max,
                           isVisible: false,
                           rangeController: _rangeController),
                       primaryYAxis: NumericAxis(isVisible: false),
                       plotAreaBorderWidth: 0,
                       series: <SplineAreaSeries<Data, double>>[
                           SplineAreaSeries<Data, double>(
                              color: Color.fromARGB(255, 126, 184, 253),
                               dataSource: chartData,
                                   xValueMapper: (Data sales, _) => sales.x,
                                   yValueMapper: (Data sales, _) => sales.y)
                            ],
                        ),
                    ),
                ),
            )
        )
    );
  }
}
Inheritance

Constructors

RangeController({@required dynamic start, @required dynamic end})
Creates a new instance of RangeController. [...]

Properties

end ↔ dynamic
The current selected end value. [...]
read / write
hashCode int
The hash code for this object. [...]
read-only, inherited
hasListeners bool
Whether any listeners are currently registered. [...]
@protected, read-only, inherited
previousEnd → dynamic
The previously selected end value. [...]
read-only
previousStart → dynamic
The previously selected start value. [...]
read-only
runtimeType Type
A representation of the runtime type of the object.
read-only, inherited
start ↔ dynamic
The current selected start value. [...]
read / write

Methods

addListener(VoidCallback listener) → void
Register a closure to be called when the object changes. [...]
inherited
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
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed. [...]
inherited
notifyListeners() → void
Call all the registered listeners. [...]
removeListener(VoidCallback listener) → void
Remove a previously registered closure from the list of closures that are notified when the object changes. [...]
inherited
toString() String
Returns a string representation of this object.
inherited

Operators

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