Skip to main content

RangeSlider

Struct RangeSlider 

Source
pub struct RangeSlider {
Show 16 fields pub key: Option<KeyRef>, pub values: RangeValues, pub on_changed: Option<ValueChanged<RangeValues>>, pub on_change_start: Option<ValueChanged<RangeValues>>, pub on_change_end: Option<ValueChanged<RangeValues>>, pub min: f64, pub max: f64, pub divisions: Option<i32>, pub labels: Option<RangeLabels>, pub active_color: Option<Color>, pub inactive_color: Option<Color>, pub overlay_color: Option<WidgetStatePropertyRef<Option<Color>>>, pub mouse_cursor: Option<WidgetStatePropertyRef<Option<MouseCursorRef>>>, pub semantic_formatter_callback: Option<SemanticFormatterCallback>, pub padding: Option<EdgeInsetsGeometry>, pub year2023: Option<bool>,
}
Expand description

A Material Design range slider.

Used to select a range from a range of values.

A range slider can be used to select from either a continuous or a discrete set of values. The default is to use a continuous range of values from min to max. To use discrete values, use a non-null value for divisions, which indicates the number of discrete intervals. For example, if min is 0.0 and max is 50.0 and divisions is 5, then the slider can take on the discrete values 0.0, 10.0, 20.0, 30.0, 40.0, and 50.0.

The terms for the parts of a slider are:

  • The “thumbs”, which are the shapes that slide horizontally when the user drags them to change the selected range.
  • The “track”, which is the horizontal line that the thumbs can be dragged along.
  • The “tick marks”, which mark the discrete values of a discrete slider.
  • The “overlay”, which is a highlight that’s drawn over a thumb in response to a user tap-down gesture.
  • The “value indicators”, which are the shapes that pop up when the user is dragging a thumb to show the value being selected.
  • The “active” segment of the slider is the segment between the two thumbs.
  • The “inactive” slider segments are the two track intervals outside of the slider’s thumbs.

The range slider will be disabled if on_changed is null or if the range given by min..max is empty (i.e. if min is equal to max).

The range slider widget itself does not maintain any state. Instead, when the state of the slider changes, the widget calls the on_changed callback. Most widgets that use a range slider will listen for the on_changed callback and rebuild the slider with new values to update the visual appearance of the slider. To know when the value starts to change, or when it is done changing, set the optional callbacks on_change_start and/or on_change_end.

By default, a slider will be as wide as possible, centered vertically. When given unbounded constraints, it will attempt to make the track 144 pixels wide (including margins on each side) and will shrink-wrap vertically.

Requires one of its ancestors to be a Material widget. This is typically provided by a Scaffold widget.

Requires one of its ancestors to be a MediaQuery widget. Typically, a MediaQuery widget is introduced by the MaterialApp or WidgetsApp widget at the top of your application widget tree.

To determine how it should be displayed (e.g. colors, thumb shape, etc.), a slider uses the SliderThemeData available from either a SliderTheme widget, or the ThemeData::slider_theme inside a Theme widget above it in the widget tree. You can also override some of the colors with the active_color and inactive_color properties, although more fine-grained control of the colors, and other visual properties is achieved using a SliderThemeData.

See also:

Fields§

§key: Option<KeyRef>§values: RangeValues

The currently selected values for this range slider.

The slider’s thumbs are drawn at horizontal positions that corresponds to these values.

§on_changed: Option<ValueChanged<RangeValues>>

Called when the user is selecting a new value for the slider by dragging.

The slider passes the new values to the callback but does not actually change state until the parent widget rebuilds the slider with the new values.

If null, the slider will be displayed as disabled.

The callback provided to on_changed should update the state of the parent StatefulWidget using the State::set_state method, so that the parent gets rebuilt.

See also:

  • on_change_start, which is called when the user starts changing the values.
  • on_change_end, which is called when the user stops changing the values.
§on_change_start: Option<ValueChanged<RangeValues>>

Called when the user starts selecting new values for the slider.

This callback shouldn’t be used to update the slider values (use on_changed for that). Rather, it should be used to be notified when the user has started selecting a new value by starting a drag or with a tap.

The values passed will be the last values that the slider had before the change began.

See also:

  • on_change_end for a callback that is called when the value change is complete.
§on_change_end: Option<ValueChanged<RangeValues>>

Called when the user is done selecting new values for the slider.

This differs from on_changed because it is only called once at the end of the interaction, while on_changed is called as the value is getting updated within the interaction.

This callback shouldn’t be used to update the slider values (use on_changed for that). Rather, it should be used to know when the user has completed selecting a new values by ending a drag or a click.

See also:

  • on_change_start for a callback that is called when a value change begins.
§min: f64

The minimum value the user can select.

Defaults to 0.0. Must be less than or equal to max.

If the max is equal to the min, then the slider is disabled.

§max: f64

The maximum value the user can select.

Defaults to 1.0. Must be greater than or equal to min.

If the max is equal to the min, then the slider is disabled.

§divisions: Option<i32>

The number of discrete divisions.

Typically used with labels to show the current discrete values.

If null, the slider is continuous.

§labels: Option<RangeLabels>

Labels to show as text in the SliderThemeData::range_value_indicator_shape when the slider is active and SliderThemeData::show_value_indicator is satisfied.

There are two labels: one for the start thumb and one for the end thumb.

Each label is rendered using the active ThemeData’s TextTheme::body_large text style, with the theme data’s ColorScheme::on_primary color. The label’s text style can be overridden with SliderThemeData::value_indicator_text_style.

If null, then the value indicator will not be displayed.

See also:

  • RangeSliderValueIndicatorShape for how to create a custom value indicator shape.
§active_color: Option<Color>

The color of the track’s active segment, i.e. the span of track between the thumbs.

Defaults to ColorScheme::primary of the ambient ThemeData.

Using a SliderTheme gives more fine-grained control over the appearance of various components of the slider.

§inactive_color: Option<Color>

The color of the track’s inactive segments, i.e. the span of tracks between the min and the start thumb, and the end thumb and the max.

Defaults to ColorScheme::primary with 24% opacity of the ambient ThemeData.

Using a SliderTheme gives more fine-grained control over the appearance of various components of the slider.

§overlay_color: Option<WidgetStatePropertyRef<Option<Color>>>

The highlight color that’s typically used to indicate that the range slider thumb is in WidgetState::Hovered or WidgetState::Dragged states.

If this property is null, RangeSlider will use active_color with an opacity of 0.12, SliderThemeData::overlay_color, or the default value of ColorScheme::primary with an opacity of 0.12.

§mouse_cursor: Option<WidgetStatePropertyRef<Option<MouseCursorRef>>>

The cursor for a mouse pointer when it enters or is hovering over the widget.

If null, then the value of SliderThemeData::mouse_cursor is used. If that is also null, then WidgetStateMouseCursor::clickable is used.

See also:

  • WidgetStateMouseCursor, which can be used to create a MouseCursor that is also a WidgetStateProperty<MouseCursor>.
§semantic_formatter_callback: Option<SemanticFormatterCallback>

The callback used to create a semantic value from the slider’s values.

Defaults to formatting values as a percentage.

Waits with accessibility: the callback is held and not called.

§padding: Option<EdgeInsetsGeometry>

The padding between the slider and the edge of its bounds.

If it is null, the value of SliderThemeData::padding is used. If that is also null, the default padding is the same as the thumb overlay, which is 24 on each side.

§year2023: Option<bool>

When true, the RangeSlider will use the 2023 Material Design appearance. If not set, then the RangeSlider will behave as if this is set to true, or the value of SliderThemeData::year2023.

If this is set to false, the RangeSlider will use the latest Material Design appearance, which was introduced in December 2023.

Defaults to true.

Implementations§

Source§

impl RangeSlider

Source

pub fn new( values: RangeValues, on_changed: Option<ValueChanged<RangeValues>>, ) -> RangeSlider

Creates a Material Design range slider.

The range slider widget itself does not maintain any state. Instead, when the state of the slider changes, the widget calls the on_changed callback. Most widgets that use a range slider will listen for the on_changed callback and rebuild the slider with new values to update the visual appearance of the slider. To know when the value starts to change, or when it is done changing, set the optional callbacks on_change_start and/or on_change_end.

  • values, which determines currently selected values for this range slider.
  • on_changed, which is called while the user is selecting a new value for the range slider.
  • on_change_start, which is called when the user starts to select a new value for the range slider.
  • on_change_end, which is called when the user is done selecting a new value for the range slider.

You can override some of the colors with the active_color and inactive_color properties, although more fine-grained control of the appearance is achieved using a SliderThemeData.

The min must be less than or equal to the max.

The RangeValues::start attribute of the values parameter must be less than or equal to its RangeValues::end attribute. The RangeValues::start and RangeValues::end attributes of the values parameter must be greater than or equal to the min parameter and less than or equal to the max parameter.

The divisions parameter must be null or greater than zero.

Source

pub fn key(self, key: KeyRef) -> RangeSlider

Dart RangeSlider(key:).

Source

pub fn on_change_start( self, on_change_start: impl Fn(&mut App, RangeValues) + 'static, ) -> RangeSlider

Dart RangeSlider(onChangeStart:).

Source

pub fn on_change_end( self, on_change_end: impl Fn(&mut App, RangeValues) + 'static, ) -> RangeSlider

Dart RangeSlider(onChangeEnd:).

Source

pub fn min(self, min: f64) -> RangeSlider

Dart RangeSlider(min:).

Source

pub fn max(self, max: f64) -> RangeSlider

Dart RangeSlider(max:).

Source

pub fn divisions(self, divisions: i32) -> RangeSlider

Dart RangeSlider(divisions:).

Source

pub fn labels(self, labels: RangeLabels) -> RangeSlider

Dart RangeSlider(labels:).

Source

pub fn active_color(self, active_color: Color) -> RangeSlider

Dart RangeSlider(activeColor:).

Source

pub fn inactive_color(self, inactive_color: Color) -> RangeSlider

Dart RangeSlider(inactiveColor:).

Source

pub fn overlay_color( self, overlay_color: WidgetStatePropertyRef<Option<Color>>, ) -> RangeSlider

Dart RangeSlider(overlayColor:).

Source

pub fn mouse_cursor( self, mouse_cursor: WidgetStatePropertyRef<Option<MouseCursorRef>>, ) -> RangeSlider

Dart RangeSlider(mouseCursor:).

Source

pub fn semantic_formatter_callback( self, semantic_formatter_callback: SemanticFormatterCallback, ) -> RangeSlider

Dart RangeSlider(semanticFormatterCallback:).

Source

pub fn padding(self, padding: impl Into<EdgeInsetsGeometry>) -> RangeSlider

Dart RangeSlider(padding:).

Source

pub fn year2023(self, year2023: bool) -> RangeSlider

👎Deprecated:

Set this flag to false to opt into the 2024 range slider appearance. Defaults to true. In the future, this flag will default to false. Use SliderThemeData to customize individual properties. This feature was deprecated after v3.30.0-0.1.pre.

Dart RangeSlider(year2023:).

Trait Implementations§

Source§

impl Clone for RangeSlider

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for RangeSlider

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl StatefulWidget for RangeSlider

Source§

type State = RangeSliderState

The state this widget creates.
Source§

fn key(&self) -> Option<&KeyRef>

Source§

fn debug_fill_properties( &self, _app: &App, properties: &mut DiagnosticPropertiesBuilder, )

Dart’s debugFillProperties: the properties a dump shows for this widget, in Dart’s order. Dart’s Widget base only sets the dense tree style, which the framework does.
Source§

fn debug_check_constructor(&self)

Source§

fn create_state(&self) -> RangeSliderState

Creates the mutable state for this widget at a given location in the tree. Read more
Source§

fn as_preferred_size_widget( &self, ) -> Option<&(dyn PreferredSizeWidget + 'static)>

Source§

fn type_name(&self) -> &'static str

See Widget::type_name. A stateful form another widget kind becomes (an animated or status transition widget) names the widget it wraps.

Auto Trait Implementations§

§

impl !RefUnwindSafe for RangeSlider

§

impl !Send for RangeSlider

§

impl !Sync for RangeSlider

§

impl !UnwindSafe for RangeSlider

§

impl Forget for RangeSlider

§

impl Freeze for RangeSlider
where *const RcInner<dyn Key> is !null: Freeze, PhantomData<RcInner<dyn Key>>: Freeze, *const RcInner<dyn Fn(&mut App, RangeValues)> is !null: Freeze, PhantomData<RcInner<dyn Fn(&mut App, RangeValues)>>: Freeze, *const u8 is !null: Freeze, PhantomData<u8>: Freeze, *const RcInner<dyn WidgetStateProperty<Option<Color>>> is !null: Freeze, PhantomData<RcInner<dyn WidgetStateProperty<Option<Color>>>>: Freeze, *const RcInner<dyn WidgetStateProperty<Option<Rc<dyn MouseCursor>>>> is !null: Freeze, PhantomData<RcInner<dyn WidgetStateProperty<Option<Rc<dyn MouseCursor>>>>>: Freeze, *const RcInner<dyn Fn(f64) -> String> is !null: Freeze, PhantomData<RcInner<dyn Fn(f64) -> String>>: Freeze,

§

impl Move for RangeSlider

§

impl Unpin for RangeSlider

§

impl UnsafeUnpin for RangeSlider
where *const RcInner<dyn Key> is !null: UnsafeUnpin, PhantomData<RcInner<dyn Key>>: UnsafeUnpin, *const RcInner<dyn Fn(&mut App, RangeValues)> is !null: UnsafeUnpin, PhantomData<RcInner<dyn Fn(&mut App, RangeValues)>>: UnsafeUnpin, *const u8 is !null: UnsafeUnpin, PhantomData<u8>: UnsafeUnpin, *const RcInner<dyn WidgetStateProperty<Option<Color>>> is !null: UnsafeUnpin, PhantomData<RcInner<dyn WidgetStateProperty<Option<Color>>>>: UnsafeUnpin, *const RcInner<dyn WidgetStateProperty<Option<Rc<dyn MouseCursor>>>> is !null: UnsafeUnpin, PhantomData<RcInner<dyn WidgetStateProperty<Option<Rc<dyn MouseCursor>>>>>: UnsafeUnpin, *const RcInner<dyn Fn(f64) -> String> is !null: UnsafeUnpin, PhantomData<RcInner<dyn Fn(f64) -> String>>: UnsafeUnpin,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<W> IntoWidget<StatefulKind> for W
where W: StatefulWidget,

Source§

fn into_widget(self) -> Rc<dyn Widget>

The widget as a tree node, made where this is called: its creation_location.
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>