| layout | post |
|---|---|
| title | Basic features in Flutter Range Slider widget | Syncfusion |
| description | Learn here all about adding the basic features in Syncfusion Flutter Range Slider (SfRangeSlider) widget and more. |
| platform | Flutter |
| control | SfRangeSlider |
| documentation | ug |
This section explains about how to add the numeric and date range slider.
The minimum value that the user can select. The default value of min property is 0.0 and it must be less than the max value.
The maximum value that the user can select. The default value of max property is 1.0 and it must be greater than the min value.
It represents the values currently selected in the range slider. The range slider's thumb is drawn corresponding to this value.
For date values, the range slider does not have auto interval support. So, it is mandatory to set interval, dateIntervalType, and dateFormat for date values.
Numeric range slider
You can show numeric values in the range slider by setting double values to the min, max and values properties.
{% tabs %} {% highlight Dart %}
SfRangeValues _values = SfRangeValues(3.0, 7.0);
@override Widget build(BuildContext context) { return MaterialApp( home: Scaffold( body: Center( child: SfRangeSlider( min: 0.0, max: 10.0, values: _values, interval: 2, showLabels: true, onChanged: (SfRangeValues newValues) { setState(() { _values = newValues; }); }, ) ) ) ); }
{% endhighlight %} {% endtabs %}
{% tabs %} {% highlight Dart %}
SfRangeValues _values = SfRangeValues(3.0, 7.0);
@override Widget build(BuildContext context) { return MaterialApp( home: Scaffold( body: Center( child: SfRangeSlider.vertical( min: 0.0, max: 10.0, values: _values, interval: 2, showLabels: true, onChanged: (SfRangeValues newValues) { setState(() { _values = newValues; }); }, ) ) ) ); }
{% endhighlight %} {% endtabs %}
Date range slider
You can show date values in the range slider by setting DateTime values to the min, max and values properties.
N> You must import intl package for formatting date range slider using the DateFormat class.
{% tabs %} {% highlight Dart %}
SfRangeValues _values = SfRangeValues(DateTime(2002, 01, 01), DateTime(2004, 01, 01));
@override Widget build(BuildContext context) { return MaterialApp( home: Scaffold( body: Center( child: SfRangeSlider( min: DateTime(2000, 01, 01, 00), max: DateTime(2004, 12, 31, 24), values: _values, interval: 1, showLabels: true, dateFormat: DateFormat.y(), dateIntervalType: DateIntervalType.years, onChanged: (SfRangeValues newValues) { setState(() { _values = newValues; }); }, ) ) ) ); }
{% endhighlight %} {% endtabs %}
{% tabs %} {% highlight Dart %}
SfRangeValues _values = SfRangeValues(DateTime(2002, 01, 01), DateTime(2004, 01, 01));
@override Widget build(BuildContext context) { return MaterialApp( home: Scaffold( body: Center( child: SfRangeSlider.vertical( min: DateTime(2000, 01, 01, 00), max: DateTime(2004, 12, 31, 24), values: _values, interval: 1, showLabels: true, dateFormat: DateFormat.y(), dateIntervalType: DateIntervalType.years, onChanged: (SfRangeValues newValues) { setState(() { _values = newValues; }); }, ) ) ) ); }
{% endhighlight %} {% endtabs %}
onChangeStart
The onChangeStart callback is called when the user begins to interact with range slider using a tap or drag action. This callback is only used to notify the user that the interaction has started and it does not change the value of the range slider thumb.
{% tabs %} {% highlight Dart %}
SfRangeValues _values = SfRangeValues(4.0, 6.0);
@override Widget build(BuildContext context) { return Scaffold( body: SfRangeSlider( min: 0.0, max: 10.0, values: _values, onChangeStart: (SfRangeValues startValues) { print('Interaction started'); }, onChanged: (SfRangeValues newValues) { setState(() { _values = newValues; }); }, ), ); }
{% endhighlight %} {% endtabs %}
onChangeEnd
The onChangeEnd callback is called when the user stops to interact with range slider using a tap or drag action. This callback is only used to notify the user that the interaction has ended and it does not change the value of the range slider thumb.
{% tabs %} {% highlight Dart %}
SfRangeValues _values = SfRangeValues(4.0, 6.0);
@override Widget build(BuildContext context) { return Scaffold( body: SfRangeSlider( min: 0.0, max: 10.0, values: _values, onChangeEnd: (SfRangeValues endValues) { print('Interaction ended'); }, onChanged: (SfRangeValues newValues) { setState(() { _values = newValues; }); }, ), ); }
{% endhighlight %} {% endtabs %}
onChanged
The onChanged callback is called when the user selects a value through interaction.
N> The range slider passes the new values to the callback but does not change its state until the parent widget rebuilds the range slider with new values.
N> If it is null, the range slider will be disabled.
{% tabs %} {% highlight Dart %}
SfRangeValues _values = SfRangeValues(3.0, 7.0);
@override Widget build(BuildContext context) { return MaterialApp( home: Scaffold( body: Center( child: SfRangeSlider( min: 0.0, max: 10.0, values: _values, onChanged: (SfRangeValues newValues) { setState(() { _values = newValues; }); }, ) ) ) ); }
{% endhighlight %} {% endtabs %}
{% tabs %} {% highlight Dart %}
SfRangeValues _values = SfRangeValues(3.0, 7.0);
@override Widget build(BuildContext context) { return MaterialApp( home: Scaffold( body: Center( child: SfRangeSlider.vertical( min: 0.0, max: 10.0, values: _values, onChanged: (SfRangeValues newValues) { setState(() { _values = newValues; }); }, ) ) ) ); }
{% endhighlight %} {% endtabs %}
It represents the color applied to the active track, thumb, overlay, and inactive dividers. The active side of the range slider is between the start and end thumbs.
{% tabs %} {% highlight Dart %}
SfRangeValues _values = SfRangeValues(3.0, 7.0);
@override Widget build(BuildContext context) { return MaterialApp( home: Scaffold( body: Center( child: SfRangeSlider( min: 0.0, max: 10.0, values: _values, activeColor: Colors.red, showDividers: true, onChanged: (SfRangeValues newValues) { setState(() { _values = newValues; }); }, ) ) ) ); }
{% endhighlight %} {% endtabs %}
{% tabs %} {% highlight Dart %}
SfRangeValues _values = SfRangeValues(3.0, 7.0);
@override Widget build(BuildContext context) { return MaterialApp( home: Scaffold( body: Center( child: SfRangeSlider.vertical( min: 0.0, max: 10.0, values: _values, activeColor: Colors.red, showDividers: true, onChanged: (SfRangeValues newValues) { setState(() { _values = newValues; }); }, ) ) ) ); }
{% endhighlight %} {% endtabs %}
It represents the color applied to the inactive track and active dividers.
The inactive side of the range slider is between the min value and the left thumb, and the right thumb and the max value.
For RTL, the inactive side is between the max value and the left thumb, and the right thumb and the min value.
{% tabs %} {% highlight Dart %}
SfRangeValues _values = SfRangeValues(3.0, 7.0);
@override Widget build(BuildContext context) { return MaterialApp( home: Scaffold( body: Center( child: SfRangeSlider( min: 0.0, max: 10.0, values: _values, activeColor: Colors.red, inactiveColor: Colors.red.withOpacity(0.2), showDividers: true, onChanged: (SfRangeValues newValues) { setState(() { _values = newValues; }); }, ) ) ) ); }
{% endhighlight %} {% endtabs %}
{% tabs %} {% highlight Dart %}
SfRangeValues _values = SfRangeValues(3.0, 7.0);
@override Widget build(BuildContext context) { return MaterialApp( home: Scaffold( body: Center( child: SfRangeSlider.vertical( min: 0.0, max: 10.0, values: _values, activeColor: Colors.red, inactiveColor: Colors.red.withOpacity(0.2), showDividers: true, onChanged: (SfRangeValues newValues) { setState(() { _values = newValues; }); }, ) ) ) ); }
{% endhighlight %} {% endtabs %}









