Skip to main content
Chromia UI provides two slider components for value selection: ChromiaSlider for single values and ChromiaRangeSlider for value ranges.

ChromiaSlider

A customizable slider component for selecting a single value from a range.

Basic Usage

import 'package:chromia_ui/chromia_ui.dart';

double currentValue = 50.0;

ChromiaSlider(
  value: currentValue,
  min: 0,
  max: 100,
  onChanged: (value) => setState(() => currentValue = value),
)

With Labels

Display minimum and maximum labels:
ChromiaSlider(
  value: currentValue,
  min: 0,
  max: 100,
  minLabel: '0',
  maxLabel: '100',
  onChanged: (value) => setState(() => currentValue = value),
)

With Value Display

Show the current value with a custom formatter:
ChromiaSlider(
  value: currentValue,
  min: 0,
  max: 100,
  minLabel: '0',
  maxLabel: '100',
  valueBuilder: (value) => '${value.toInt()}%',
  onChanged: (value) => setState(() => currentValue = value),
)

Discrete Steps

Create a slider with discrete divisions:
ChromiaSlider(
  value: currentValue,
  min: 0,
  max: 100,
  divisions: 10, // Creates 11 discrete values (0, 10, 20, ...100)
  label: '${currentValue.toInt()}',
  onChanged: (value) => setState(() => currentValue = value),
)

Custom Colors

Customize the slider colors:
ChromiaSlider(
  value: currentValue,
  min: 0,
  max: 100,
  activeColor: Colors.green,
  inactiveColor: Colors.grey.shade300,
  thumbColor: Colors.green.shade700,
  onChanged: (value) => setState(() => currentValue = value),
)

Custom Track Height

Adjust the slider track height:
ChromiaSlider(
  value: currentValue,
  min: 0,
  max: 100,
  trackHeight: 12,
  onChanged: (value) => setState(() => currentValue = value),
)

Custom Thumb Size

Adjust the thumb (handle) size:
ChromiaSlider(
  value: currentValue,
  min: 0,
  max: 100,
  thumbRadius: 16,
  onChanged: (value) => setState(() => currentValue = value),
)

With Thumb Icon

Add an icon to the slider thumb:
ChromiaSlider(
  value: volume,
  min: 0,
  max: 100,
  thumbIcon: Icons.volume_up,
  onChanged: (value) => setState(() => volume = value),
)

Disabled State

Disable the slider:
ChromiaSlider(
  value: currentValue,
  min: 0,
  max: 100,
  enabled: false,
  onChanged: null,
)

ChromiaSlider Parameters

value
double
required
The current value of the slider.
onChanged
ValueChanged<double>?
required
Called when the value changes. Set to null to disable.
min
double
default:"0.0"
Minimum value.
max
double
default:"1.0"
Maximum value.
divisions
int?
Number of discrete divisions. If null, slider is continuous.
label
String?
Label to show above the slider thumb.
minLabel
String?
Label for minimum value (displayed below slider).
maxLabel
String?
Label for maximum value (displayed below slider).
activeColor
Color?
Color of the active portion of the slider.
inactiveColor
Color?
Color of the inactive portion of the slider.
thumbColor
Color?
Color of the slider thumb.
valueBuilder
String Function(double)?
Custom value formatter for display.
enabled
bool
default:"true"
Whether the slider is enabled.
trackHeight
double
default:"8"
Height of the slider track.
thumbRadius
double?
Radius of the slider thumb.
thumbIcon
IconData?
Icon to display on the slider thumb.
thumbShape
SliderComponentShape?
Custom shape for the slider thumb.

ChromiaRangeSlider

A range slider for selecting a range of values.

Basic Usage

RangeValues currentRange = RangeValues(20, 80);

ChromiaRangeSlider(
  values: currentRange,
  min: 0,
  max: 100,
  onChanged: (values) => setState(() => currentRange = values),
)

With Value Display

Show the current range values:
ChromiaRangeSlider(
  values: currentRange,
  min: 0,
  max: 100,
  showValues: true,
  onChanged: (values) => setState(() => currentRange = values),
)

With Custom Formatter

ChromiaRangeSlider(
  values: priceRange,
  min: 0,
  max: 1000,
  showValues: true,
  valueBuilder: (value) => '\$${value.toInt()}',
  onChanged: (values) => setState(() => priceRange = values),
)

Discrete Range

ChromiaRangeSlider(
  values: currentRange,
  min: 0,
  max: 100,
  divisions: 10,
  labels: RangeLabels(
    '${currentRange.start.toInt()}',
    '${currentRange.end.toInt()}',
  ),
  onChanged: (values) => setState(() => currentRange = values),
)

With Thumb Icons

Add icons to both thumbs:
ChromiaRangeSlider(
  values: timeRange,
  min: 0,
  max: 24,
  startThumbIcon: Icons.wb_sunny,
  endThumbIcon: Icons.nightlight,
  showValues: true,
  valueBuilder: (value) => '${value.toInt()}:00',
  onChanged: (values) => setState(() => timeRange = values),
)

Custom Colors

ChromiaRangeSlider(
  values: currentRange,
  min: 0,
  max: 100,
  activeColor: Colors.blue,
  inactiveColor: Colors.grey.shade300,
  showValues: true,
  onChanged: (values) => setState(() => currentRange = values),
)

Disabled Range Slider

ChromiaRangeSlider(
  values: currentRange,
  min: 0,
  max: 100,
  enabled: false,
  onChanged: null,
)

ChromiaRangeSlider Parameters

values
RangeValues
required
The current range values.
onChanged
ValueChanged<RangeValues>?
required
Called when the values change. Set to null to disable.
min
double
default:"0.0"
Minimum value.
max
double
default:"1.0"
Maximum value.
divisions
int?
Number of discrete divisions.
labels
RangeLabels?
Labels to show above the thumbs.
activeColor
Color?
Color of the active portion.
inactiveColor
Color?
Color of the inactive portion.
showValues
bool
default:"false"
Whether to show the values below the slider.
valueBuilder
String Function(double)?
Custom value formatter.
enabled
bool
default:"true"
Whether the slider is enabled.
trackHeight
double
default:"8"
Height of the slider track.
thumbRadius
double?
Radius of the slider thumbs.
startThumbIcon
IconData?
Icon to display on the start thumb.
endThumbIcon
IconData?
Icon to display on the end thumb.
rangeThumbShape
RangeSliderThumbShape?
Custom shape for the slider thumbs.

Use Cases

Volume Control

double volume = 50;

ChromiaSlider(
  value: volume,
  min: 0,
  max: 100,
  thumbIcon: Icons.volume_up,
  minLabel: '0%',
  maxLabel: '100%',
  valueBuilder: (value) => '${value.toInt()}%',
  onChanged: (value) {
    setState(() => volume = value);
    // Update audio volume
  },
)

Price Range Filter

RangeValues priceRange = RangeValues(50, 500);

ChromiaRangeSlider(
  values: priceRange,
  min: 0,
  max: 1000,
  divisions: 20,
  showValues: true,
  valueBuilder: (value) => '\$${value.toInt()}',
  onChanged: (values) {
    setState(() => priceRange = values);
    // Apply price filter
  },
)

Brightness Control

double brightness = 0.7;

ChromiaSlider(
  value: brightness,
  min: 0,
  max: 1,
  thumbIcon: Icons.brightness_6,
  divisions: 10,
  onChanged: (value) {
    setState(() => brightness = value);
    // Update screen brightness
  },
)

Age Range Selector

RangeValues ageRange = RangeValues(18, 65);

ChromiaRangeSlider(
  values: ageRange,
  min: 0,
  max: 100,
  showValues: true,
  valueBuilder: (value) => '${value.toInt()} years',
  labels: RangeLabels(
    '${ageRange.start.toInt()}',
    '${ageRange.end.toInt()}',
  ),
  onChanged: (values) => setState(() => ageRange = values),
)

Build docs developers (and LLMs) love