Slider
A draggable slider component for selecting values within a range
A draggable slider component for selecting values within a continuous range.
When to use this
- Volume controls: Adjust audio or video volume levels
- Brightness settings: Control screen brightness or lighting
- Price filters: Select price ranges in e-commerce applications
- Value adjustments: Set any numeric value within a defined range
Basic implementation
Basic implementation
import 'package:flutter/material.dart';
import 'package:remix/remix.dart';
class SliderExample extends StatefulWidget {
const SliderExample({super.key});
@override
State<SliderExample> createState() => _SliderExampleState();
}
class _SliderExampleState extends State<SliderExample> {
double _selectedValue = 0.3;
@override
Widget build(BuildContext context) {
return SizedBox(
width: 300,
child: RemixSlider(
value: _selectedValue,
style: style,
onChanged: (value) {
setState(() {
_selectedValue = value;
});
},
),
);
}
SliderStyler get style {
return SliderStyler()
.thumbSize(const Size(24, 24))
.thumb(
BoxStyler().shape(.circle()).shadow(
BoxShadowMix()
.color(Colors.black45)
.blurRadius(4)
.offset(x: 0, y: 2),
),
)
.thumbColor(Colors.black)
.thickness(2)
.trackColor(Colors.grey.shade300)
.rangeColor(Colors.black)
.onDisabled(
SliderStyler()
.trackColor(Colors.grey.shade300)
.rangeColor(Colors.blueGrey)
.thumbColor(Colors.white.withValues(alpha: 0.6)),
);
}
}Two-bound intervals
Use RemixRangeSlider for a lower and upper bound. The parent owns both values;
accept a request by rebuilding with the returned list. Supply distinct localized
names and formatters for each thumb.
import 'package:flutter/widgets.dart';
import 'package:remix/remix.dart';
class PriceRange extends StatefulWidget {
const PriceRange({super.key});
@override
State<PriceRange> createState() => _PriceRangeState();
}
class _PriceRangeState extends State<PriceRange> {
List<double> prices = [80, 240];
@override
Widget build(BuildContext context) => SizedBox(
width: 280,
child: RemixRangeSlider(
values: prices,
min: 0,
max: 400,
minSpacing: 20,
snapDivisions: 80,
semanticLabels: const ['Minimum nightly price', 'Maximum nightly price'],
semanticFormatterCallbacks: [
(value) => '\$${value.round()} per night',
(value) => '\$${value.round()} per night',
],
onChanged: (next) => setState(() => prices = next),
style: SliderStyler()
.thumbSize(const Size(20, 20))
.thumbColor(const Color(0xff42654b))
.thickness(4)
.trackColor(const Color(0xffd5ddd1))
.rangeColor(const Color(0xff42654b)),
),
);
}The list must contain exactly two finite, ordered values within min and max,
separated by at least minSpacing (default zero). Thumbs can touch but never push,
cross, or swap identities. From coincident values, movement toward smaller values
opens the lower bound; movement toward larger values opens the upper bound.
Horizontal placement and arrow keys respect ambient RTL direction.
focusNodes, semanticLabels and semanticFormatterCallbacks use lower/upper
order. autofocusThumbIndex accepts 0 or 1. Tab visits lower then upper; arrow,
Home/End and Page keys adjust the focused thumb. Semantic increase/decrease acts
on its corresponding bound. excludeSemantics hides both nodes while retaining
keyboard operation. A null onChanged or enabled: false disables interaction.
onChanged receives complete immutable requests from pointer, keyboard and
semantic input. onChangeStart and onChangeEnd are pointer-only: one start on
down, and one end on release or cancellation. End reports the last request, even
when the parent rejected it. Without snapDivisions, the step is one thousandth
of the domain. Neighbor spacing and domain bounds take precedence over snapping,
so a constrained request may lie off the division grid.
Both widgets reuse SliderStyler and SliderSpec. Track/range styling uses
aggregate state; each range thumb resolves its own focused, pressed and hovered
state. Root modifiers apply once; nested thumb modifiers apply per thumb. A raw
styleSpec bypasses fluent and inherited styles. Forwarded width, constraints,
margin and padding style the thumb, so constrain overall width with a parent.
The range hit area is at least 48 logical pixels high; single-slider dimensions
and SliderStyler.call(value: ...) remain unchanged. The range is horizontal;
use NakedSlider for custom arbitrary-thumb or vertical anatomy.
Vanilla widgets
Install the range recipe into an app initialized with the Vanilla preset:
remix add range_sliderThis installs slider and theme as dependencies. With prefix Ui, import
ui/ui.dart and place UiTheme in the app's builder. The single-value
UiSlider and two-bound UiRangeSlider share the same rail, interval and
thumb styling. Hover, press and keyboard focus draw a 4px ring around the
corresponding thumb; disabled fades the complete control.
import 'package:flutter/widgets.dart';
import 'ui/ui.dart';
class VanillaPriceRange extends StatefulWidget {
const VanillaPriceRange({super.key});
@override
State<VanillaPriceRange> createState() => _VanillaPriceRangeState();
}
class _VanillaPriceRangeState extends State<VanillaPriceRange> {
List<double> prices = [80, 240];
@override
Widget build(BuildContext context) => SizedBox(
width: 280,
child: UiRangeSlider(
values: prices,
min: 0,
max: 400,
minSpacing: 20,
snapDivisions: 80,
semanticLabels: const ['Minimum nightly price', 'Maximum nightly price'],
onChanged: (next) => setState(() => prices = next),
),
);
}The generated adapter forwards the range API except styleSpec and
semanticFormatterCallbacks. For localized value formatting, keep
RemixRangeSlider and set style: uiRangeSliderStyle() instead. Caller
style overrides merge last, including state fragments.
Fortal widgets
Fortal also installs range_slider, sharing the single slider's surface/soft
variants, three sizes, high contrast, and 48px interaction height. Each thumb
has its own hover halo, pressed edge and contiguous visible-focus ring.
Disabled intervals remain visible in both modes. Use the base
RemixRangeSlider with uiRangeSliderStyle() for custom announcements.
The application-owned Fortal preset provides a themed widget for this component:
Fortal variants
import 'package:flutter/material.dart';
import 'ui/ui.dart';
class FortalSliderExample extends StatefulWidget {
const FortalSliderExample({super.key});
@override
State<FortalSliderExample> createState() => _FortalSliderExampleState();
}
class _FortalSliderExampleState extends State<FortalSliderExample> {
double _value = 0.5;
@override
Widget build(BuildContext context) {
return Column(
spacing: 16,
children: [
FortalSlider.surface(
value: _value,
onChanged: (v) => setState(() => _value = v),
),
FortalSlider.soft(
value: _value,
onChanged: (v) => setState(() => _value = v),
),
],
);
}
}See the fortalSliderStyle source code for all available options.
HeroUI widgets
remix add range_slider also works in a HeroUI app. UiRangeSlider delegates
to uiSliderStyle() for the pill track, accent interval and both ringed
thumbs. Press scales only the active thumb; keyboard focus rings only the
focused thumb. Hover keeps HeroUI v3's resting paint. Disabled fades the
complete control. The range has a 48px interaction height, and keeps the same
values, minSpacing, snapping and semanticLabels API shown above.
Constructor
Constructor
import 'package:flutter/material.dart';
import 'package:naked_ui/naked_ui.dart';
import 'package:remix/remix.dart';
RemixSlider remixSliderConstructor({
Key? key,
required double value,
ValueChanged<double>? onChanged,
ValueChanged<double>? onChangeStart,
ValueChanged<double>? onChangeEnd,
double min = 0.0,
double max = 1.0,
bool enabled = true,
bool enableFeedback = true,
FocusNode? focusNode,
bool autofocus = false,
int? snapDivisions,
String? semanticLabel,
NakedSliderSemanticFormatterCallback? semanticFormatterCallback,
bool excludeSemantics = false,
SliderStyler style = const SliderStyler.create(),
SliderSpec? styleSpec,
}) => throw UnimplementedError();Properties
RemixSlider properties
key → Key?
Optional. Controls how one widget replaces another widget in the tree.
min → double
Optional. The minimum value the slider can have. Must be strictly less than max.
max → double
Optional. The maximum value the slider can have. Must be strictly greater than min.
onChanged → ValueChanged<double>?
Optional. Called during pointer, keyboard or semantic input with the new value. When omitted, the slider is disabled.
value → double
Required. The current value of the slider. Must be between [min] and [max].
onChangeEnd → ValueChanged<double>?
Optional. Called at pointer release or cancellation with the last requested value.
onChangeStart → ValueChanged<double>?
Optional. Called when a pointer transaction begins.
style → SliderStyler
Optional. The style configuration for the slider.
styleSpec → SliderSpec?
Optional. The style spec for the slider.
enabled → bool
Optional. Whether the slider is enabled for interaction.
enableFeedback → bool
Optional. Whether to provide platform feedback during value changes. Defaults to true.
focusNode → FocusNode?
Optional. The focus node for the slider.
autofocus → bool
Optional. Whether the slider should automatically request focus when it is created.
snapDivisions → int?
Optional. Optional snapping divisions for interaction only (no visual ticks). When provided it must be greater than 0, and the slider snaps to these discrete steps but does not render any division marks on the track.
semanticLabel → String?
Optional. The accessible label for the slider's single thumb.
semanticFormatterCallback → NakedSliderSemanticFormatterCallback?
Optional. Formats the semantic value for the slider's single thumb. Remix forwards it to Naked as a one-element formatter list.
excludeSemantics → bool
Optional. Whether to hide the slider from the semantics tree. Defaults to false.
RemixRangeSlider properties
| Property | Type | Default | Description |
|---|---|---|---|
key | Key? | null | Controls widget replacement. |
values | List<double> | Required | Exactly two finite, ordered bounds within the domain, separated by at least minSpacing. |
min | double | 0 | Finite lower domain bound, strictly less than max. |
max | double | 1 | Finite upper domain bound. |
minSpacing | double | 0 | Finite, nonnegative minimum separation in value units. |
snapDivisions | int? | null | Positive interaction divisions without visible ticks. Null uses 1000 divisions. |
onChanged | ValueChanged<List<double>>? | null | Receives immutable complete requests. Null disables interaction. |
onChangeStart | ValueChanged<List<double>>? | null | Receives starting values when a pointer transaction begins. |
onChangeEnd | ValueChanged<List<double>>? | null | Receives the last request at pointer release or cancellation, even if the parent rejected it. |
enabled | bool | true | Enables interaction when onChanged is also supplied. |
enableFeedback | bool | true | Enables platform feedback during value changes. |
focusNodes | List<FocusNode?>? | null | Two caller-owned nodes in lower/upper order. Null entries use internal nodes. |
autofocusThumbIndex | int? | null | Initially focuses thumb 0 or 1. |
semanticLabels | List<String?>? | null | Two accessible names in lower/upper order. |
semanticFormatterCallbacks | List<NakedSliderSemanticFormatterCallback?>? | null | Two value formatters in lower/upper order. |
excludeSemantics | bool | false | Hides both semantic nodes while preserving keyboard operation. |
style | SliderStyler | const SliderStyler.create() | Fluent and inherited presentation. |
styleSpec | SliderSpec? | null | Resolved presentation that bypasses fluent and inherited styles. |
Small minSpacing values can leave the painted thumbs overlapping. The spacing
constraint measures values, not pixels; coincident bounds remain independently
keyboard accessible.
Style Methods
thumbColor(Color value)
Sets thumb color
trackColor(Color value)
Sets track color (background rail)
rangeColor(Color value)
Sets range color (filled progress portion)
thumb(BoxStyler value)
Sets thumb styling
thumbSize(Size size)
Sets thumb to a fixed [size].
alignment(Alignment value)
Sets thumb alignment
thickness(double value)
Sets stroke width for both track and range.
trackThickness(double value)
Sets stroke width for the track only (background rail).
trackWidth(double value)
Sets stroke width for the track only.
rangeThickness(double value)
Sets stroke width for the range only (filled portion).
rangeWidth(double value)
Sets stroke width for the range only.
padding(EdgeInsetsGeometryMix value)
Sets the thumb padding.
color(Color value)
Sets background color.
size(double width, double height)
Sets the thumb size.
borderRadius(BorderRadiusGeometryMix radius)
Sets the border radius.
constraints(BoxConstraintsMix value)
Sets size constraints on the thumb.
decoration(DecorationMix value)
Sets the container decoration.
margin(EdgeInsetsGeometryMix value)
Sets the container margin.
foregroundDecoration(DecorationMix value)
Sets a foreground decoration painted on top of the component.
transform(Matrix4 value, AlignmentGeometry alignment = Alignment.center)
Applies a matrix transformation to the component.
wrap(WidgetModifierConfig value)
Applies widget modifiers such as clipping, opacity, or scaling.
animate(AnimationConfig value)
Configures implicit animation for style transitions.
variants(List<VariantStyle<SliderSpec>> value)
Sets style variants.
modifier(WidgetModifierConfig value)
Sets the widget modifier.
call({Key? key, required double value, ValueChanged<double>? onChanged, ValueChanged<double>? onChangeStart, ValueChanged<double>? onChangeEnd, double min = 0.0, double max = 1.0, bool enabled = true, bool enableFeedback = true, FocusNode? focusNode, bool autofocus = false, int? snapDivisions, String? semanticLabel, NakedSliderSemanticFormatterCallback? semanticFormatterCallback, bool excludeSemantics = false})
Creates a RemixSlider widget with this style applied.