pub struct Slider {Show 23 fields
pub key: Option<KeyRef>,
pub value: f64,
pub secondary_track_value: Option<f64>,
pub on_changed: Option<ValueChanged<f64>>,
pub on_change_start: Option<ValueChanged<f64>>,
pub on_change_end: Option<ValueChanged<f64>>,
pub min: f64,
pub max: f64,
pub divisions: Option<i32>,
pub label: Option<String>,
pub active_color: Option<Color>,
pub inactive_color: Option<Color>,
pub secondary_active_color: Option<Color>,
pub thumb_color: Option<Color>,
pub overlay_color: Option<WidgetStatePropertyRef<Option<Color>>>,
pub mouse_cursor: Option<MouseCursorRef>,
pub semantic_formatter_callback: Option<SemanticFormatterCallback>,
pub focus_node: Option<FocusNodeRef>,
pub autofocus: bool,
pub allowed_interaction: Option<SliderInteraction>,
pub padding: Option<EdgeInsetsGeometry>,
pub show_value_indicator: Option<ShowValueIndicator>,
pub year2023: Option<bool>,
/* private fields */
}Expand description
A Material Design slider.
Used to select from a range of values.
A 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 “thumb”, which is a shape that slides horizontally when the user drags it.
- The “track”, which is the line that the slider thumb slides along.
- The “value indicator”, which is a shape that pops up when the user is dragging the thumb to indicate the value being selected.
- The “active” side of the slider is the side between the thumb and the minimum value.
- The “inactive” side of the slider is the side between the thumb and the maximum value.
The 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 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 slider will listen for the on_changed
callback and rebuild the slider with a new value 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 (with margins on each side) and will shrink-wrap vertically.
Requires one of its ancestors to be a Material widget.
Requires one of its ancestors to be a MediaQuery widget. Typically, these
are 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 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 look is achieved using a
SliderThemeData.
Dart’s constructor asserts run when the slider is turned into a WidgetRef
(into_widget), once every setter has run.
See also:
SliderThemeandSliderThemeDatafor information about controlling the visual appearance of the slider.Radio, for selecting among a set of explicit values.CheckboxandSwitch, for toggling a particular value on or off.- https://material.io/design/components/sliders.html
MediaQuery, from which the text scale factor is obtained.
Fields§
§key: Option<KeyRef>§value: f64The currently selected value for this slider.
The slider’s thumb is drawn at a position that corresponds to this value.
secondary_track_value: Option<f64>The secondary track value for this slider.
If not null, a secondary track using secondary_active_color
color is drawn between the thumb and this value, over the inactive track.
If less than value, then the secondary track is not shown.
It can be ideal for media scenarios such as showing the buffering progress
while the value shows the play progress.
on_changed: Option<ValueChanged<f64>>Called during a drag when the user is selecting a new value for the slider by dragging.
The slider passes the new value to the callback but does not actually change state until the parent widget rebuilds the slider with the new value.
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_startfor a callback that is called when the user starts changing the value.on_change_endfor a callback that is called when the user stops changing the value.
on_change_start: Option<ValueChanged<f64>>Called when the user starts selecting a new value for the slider.
This callback shouldn’t be used to update the slider value (use
on_changed for that), but rather to be notified when the user has
started selecting a new value by starting a drag or with a tap.
The value passed will be the last value that the slider had before the
change began.
See also:
on_change_endfor a callback that is called when the value change is complete.
on_change_end: Option<ValueChanged<f64>>Called when the user is done selecting a new value for the slider.
This callback shouldn’t be used to update the slider value (use
on_changed for that), but rather to know when the user has
completed selecting a new value by ending a drag or a click.
See also:
on_change_startfor a callback that is called when a value change begins.
min: f64The 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: f64The 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 label to show the current discrete value.
If null, the slider is continuous.
label: Option<String>A label to show inside the value indicator above the slider’s thumb.
By default, the label is shown while dragging a discrete slider, where
divisions is non-null. It can also be shown for a continuous
slider, where divisions is null, by setting
show_value_indicator to
ShowValueIndicator::OnlyForContinuous, ShowValueIndicator::OnDrag, or
ShowValueIndicator::AlwaysVisible.
If show_value_indicator is null, the ambient
SliderThemeData::show_value_indicator determines when the label is shown.
The 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.
Ignored if this slider is created with Slider::adaptive.
See also:
SliderComponentShapefor how to create a custom value indicator shape.
active_color: Option<Color>The color to use for the portion of the slider track that is active.
The “active” side of the slider is the side between the thumb and the minimum value.
If null, SliderThemeData::active_track_color of the ambient
SliderTheme is used. If that is null, ColorScheme::primary of the
surrounding ThemeData is used.
Using a SliderTheme gives much more fine-grained control over the
appearance of various components of the slider.
inactive_color: Option<Color>The color for the inactive portion of the slider track.
The “inactive” side of the slider is the side between the thumb and the maximum value.
If null, SliderThemeData::inactive_track_color of the ambient SliderTheme
is used. If year2023 is false and ThemeData::use_material3 is
true, then ColorScheme::secondary_container is used and if
ThemeData::use_material3 is false, ColorScheme::primary with an opacity of 0.24 is
used. Otherwise, ColorScheme::surface_container_highest is used.
Using a SliderTheme gives much more fine-grained control over the
appearance of various components of the slider.
Ignored if this slider is created with Slider::adaptive.
secondary_active_color: Option<Color>The color to use for the portion of the slider track between the thumb and
the secondary_track_value.
Defaults to the SliderThemeData::secondary_active_track_color of the current
SliderTheme.
If that is also null, defaults to ColorScheme::primary with an
opacity of 0.54.
Using a SliderTheme gives much more fine-grained control over the
appearance of various components of the slider.
Ignored if this slider is created with Slider::adaptive.
thumb_color: Option<Color>The color of the thumb.
If this color is null, Slider will use active_color, If
active_color is also null, Slider will use
SliderThemeData::thumb_color.
If that is also null, defaults to ColorScheme::primary.
CupertinoSliderwill have a white thumb (like the native default iOS slider).
overlay_color: Option<WidgetStatePropertyRef<Option<Color>>>The highlight color that’s typically used to indicate that the slider thumb is focused, hovered, or dragged.
If this property is null, Slider will use active_color with
an opacity of 0.12, If null, SliderThemeData::overlay_color
will be used.
If that is also null, If ThemeData::use_material3 is true,
Slider will use ColorScheme::primary with an opacity of 0.08 when
slider thumb is hovered and with an opacity of 0.1 when slider thumb
is focused or dragged, If ThemeData::use_material3 is false, defaults
to ColorScheme::primary with an opacity of 0.12.
mouse_cursor: Option<MouseCursorRef>The cursor for a mouse pointer when it enters or is hovering over the widget.
If mouse_cursor is a WidgetStateMouseCursor,
WidgetStateProperty::resolve is used for the following WidgetStates:
If null, then the value of SliderThemeData::mouse_cursor is used. If that
is also null, then WidgetStateMouseCursor::clickable is used.
semantic_formatter_callback: Option<SemanticFormatterCallback>The callback used to create a semantic value from a slider value.
Defaults to formatting values as a percentage.
This is used by accessibility frameworks like TalkBack on Android to inform users what the currently selected value is with more context.
Ignored if this slider is created with Slider::adaptive
focus_node: Option<FocusNodeRef>An optional focus node to use as the focus node for this widget.
autofocus: boolTrue if this widget will be selected as the initial focus when no other node in its scope is currently focused.
allowed_interaction: Option<SliderInteraction>Allowed way for the user to interact with the Slider.
For example, if this is set to SliderInteraction::TapOnly, the user can
interact with the slider only by tapping anywhere on the track. Sliding
will have no effect.
Defaults to SliderInteraction::TapAndSlide.
padding: Option<EdgeInsetsGeometry>Determines the padding around the Slider.
If specified, this padding overrides the default vertical padding of
the Slider, defaults to the height of the overlay shape, and the
horizontal padding, defaults to the width of the thumb shape or
overlay shape, whichever is larger.
show_value_indicator: Option<ShowValueIndicator>Determines the conditions under which the value indicator is shown.
If show_value_indicator is null then the
ambient SliderThemeData::show_value_indicator is used. If that is also
null, defaults to ShowValueIndicator::OnlyForDiscrete.
year2023: Option<bool>When true, the Slider will use the 2023 Material Design 3 appearance.
Defaults to true.
If this is set to false, the Slider will use the latest Material Design 3
appearance, which was introduced in December 2023.
If ThemeData::use_material3 is false, then this property is ignored.
Deprecated in Flutter after v3.27.0-0.1.pre; its setter carries the deprecation.
Implementations§
Source§impl Slider
impl Slider
Sourcepub fn new(value: f64, on_changed: Option<ValueChanged<f64>>) -> Slider
pub fn new(value: f64, on_changed: Option<ValueChanged<f64>>) -> Slider
Creates a Material Design slider.
The slider 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 slider will listen for the on_changed
callback and rebuild the slider with a new value to update the visual
appearance of the slider.
valuedetermines currently selected value for this slider.on_changedis called while the user is selecting a new value for the slider.on_change_startis called when the user starts to select a new value for the slider.on_change_endis called when the user is done selecting a new value for the 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.
Sourcepub fn adaptive(value: f64, on_changed: Option<ValueChanged<f64>>) -> Slider
pub fn adaptive(value: f64, on_changed: Option<ValueChanged<f64>>) -> Slider
Creates an adaptive Slider based on the target platform, following
Material design’s
Cross-platform guidelines.
Creates a CupertinoSlider if the target platform is iOS or macOS, creates a
Material Design slider otherwise.
If a CupertinoSlider is created, the following parameters are ignored:
secondary_track_value, label,
inactive_color,
secondary_active_color,
semantic_formatter_callback,
show_value_indicator.
The target platform is based on the current Theme: ThemeData::platform.
Dart’s Slider.adaptive has no padding parameter: its padding is null, so a
padding set on it is ignored (effective_padding).
Sourcepub fn secondary_track_value(self, secondary_track_value: f64) -> Slider
pub fn secondary_track_value(self, secondary_track_value: f64) -> Slider
Dart Slider(secondaryTrackValue:).
Sourcepub fn on_change_start(self, on_change_start: ValueChanged<f64>) -> Slider
pub fn on_change_start(self, on_change_start: ValueChanged<f64>) -> Slider
Dart Slider(onChangeStart:).
Sourcepub fn on_change_end(self, on_change_end: ValueChanged<f64>) -> Slider
pub fn on_change_end(self, on_change_end: ValueChanged<f64>) -> Slider
Dart Slider(onChangeEnd:).
Sourcepub fn active_color(self, active_color: Color) -> Slider
pub fn active_color(self, active_color: Color) -> Slider
Dart Slider(activeColor:).
Sourcepub fn inactive_color(self, inactive_color: Color) -> Slider
pub fn inactive_color(self, inactive_color: Color) -> Slider
Dart Slider(inactiveColor:).
Sourcepub fn secondary_active_color(self, secondary_active_color: Color) -> Slider
pub fn secondary_active_color(self, secondary_active_color: Color) -> Slider
Dart Slider(secondaryActiveColor:).
Sourcepub fn thumb_color(self, thumb_color: Color) -> Slider
pub fn thumb_color(self, thumb_color: Color) -> Slider
Dart Slider(thumbColor:).
Sourcepub fn overlay_color(
self,
overlay_color: WidgetStatePropertyRef<Option<Color>>,
) -> Slider
pub fn overlay_color( self, overlay_color: WidgetStatePropertyRef<Option<Color>>, ) -> Slider
Dart Slider(overlayColor:).
Sourcepub fn mouse_cursor(self, mouse_cursor: MouseCursorRef) -> Slider
pub fn mouse_cursor(self, mouse_cursor: MouseCursorRef) -> Slider
Dart Slider(mouseCursor:).
Sourcepub fn semantic_formatter_callback(
self,
semantic_formatter_callback: SemanticFormatterCallback,
) -> Slider
pub fn semantic_formatter_callback( self, semantic_formatter_callback: SemanticFormatterCallback, ) -> Slider
Dart Slider(semanticFormatterCallback:).
Sourcepub fn focus_node(self, focus_node: FocusNodeRef) -> Slider
pub fn focus_node(self, focus_node: FocusNodeRef) -> Slider
Dart Slider(focusNode:).
Sourcepub fn allowed_interaction(
self,
allowed_interaction: SliderInteraction,
) -> Slider
pub fn allowed_interaction( self, allowed_interaction: SliderInteraction, ) -> Slider
Dart Slider(allowedInteraction:).
Sourcepub fn padding(self, padding: impl Into<EdgeInsetsGeometry>) -> Slider
pub fn padding(self, padding: impl Into<EdgeInsetsGeometry>) -> Slider
Dart Slider(padding:).
Sourcepub fn show_value_indicator(
self,
show_value_indicator: ShowValueIndicator,
) -> Slider
pub fn show_value_indicator( self, show_value_indicator: ShowValueIndicator, ) -> Slider
Dart Slider(showValueIndicator:).
Sourcepub fn year2023(self, year2023: bool) -> Slider
👎Deprecated: Set this flag to false to opt into the 2024 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.27.0-0.1.pre.
pub fn year2023(self, year2023: bool) -> Slider
Set this flag to false to opt into the 2024 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.27.0-0.1.pre.
Dart Slider(year2023:).
Sourcepub fn effective_padding(&self) -> Option<EdgeInsetsGeometry>
pub fn effective_padding(&self) -> Option<EdgeInsetsGeometry>
Dart’s padding field: what padding was given, and null for a
slider made with Slider::adaptive, whose constructor sets it so.
Trait Implementations§
Source§impl StatefulWidget for Slider
impl StatefulWidget for Slider
Source§type State = SliderState
type State = SliderState
Source§fn debug_fill_properties(
&self,
_app: &App,
properties: &mut DiagnosticPropertiesBuilder,
)
fn debug_fill_properties( &self, _app: &App, properties: &mut DiagnosticPropertiesBuilder, )
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 create_state(&self) -> SliderState
fn create_state(&self) -> SliderState
Source§fn as_preferred_size_widget(
&self,
) -> Option<&(dyn PreferredSizeWidget + 'static)>
fn as_preferred_size_widget( &self, ) -> Option<&(dyn PreferredSizeWidget + 'static)>
Source§fn type_name(&self) -> &'static str
fn type_name(&self) -> &'static str
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 Slider
impl !Send for Slider
impl !Sync for Slider
impl !UnwindSafe for Slider
impl Forget for Slider
impl Freeze for Sliderwhere
*const RcInner<dyn Key> is !null: Freeze,
PhantomData<RcInner<dyn Key>>: Freeze,
*const RcInner<dyn Fn(&mut App, f64)> is !null: Freeze,
PhantomData<RcInner<dyn Fn(&mut App, f64)>>: 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 MouseCursor> is !null: Freeze,
PhantomData<RcInner<dyn MouseCursor>>: Freeze,
*const RcInner<dyn Fn(f64) -> String> is !null: Freeze,
PhantomData<RcInner<dyn Fn(f64) -> String>>: Freeze,
NonZero<u32>: Freeze,
&'static FocusNodeVTable: Freeze,
*const RcInner<Keep> is !null: Freeze,
PhantomData<RcInner<Keep>>: Freeze,
impl Move for Slider
impl Unpin for Slider
impl UnsafeUnpin for Sliderwhere
*const RcInner<dyn Key> is !null: UnsafeUnpin,
PhantomData<RcInner<dyn Key>>: UnsafeUnpin,
*const RcInner<dyn Fn(&mut App, f64)> is !null: UnsafeUnpin,
PhantomData<RcInner<dyn Fn(&mut App, f64)>>: 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 MouseCursor> is !null: UnsafeUnpin,
PhantomData<RcInner<dyn MouseCursor>>: UnsafeUnpin,
*const RcInner<dyn Fn(f64) -> String> is !null: UnsafeUnpin,
PhantomData<RcInner<dyn Fn(f64) -> String>>: UnsafeUnpin,
NonZeroU32Inner: UnsafeUnpin,
&'static FocusNodeVTable: UnsafeUnpin,
*const RcInner<Keep> is !null: UnsafeUnpin,
PhantomData<RcInner<Keep>>: UnsafeUnpin,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<W> IntoWidget<StatefulKind> for Wwhere
W: StatefulWidget,
impl<W> IntoWidget<StatefulKind> for Wwhere
W: StatefulWidget,
Source§fn into_widget(self) -> Rc<dyn Widget>
fn into_widget(self) -> Rc<dyn Widget>
creation_location.