Overview
HuxSlider is a customizable slider component with smooth animations, consistent styling, and automatic theme adaptation. It provides a clean, modern interface for selecting numeric values within a range while maintaining accessibility standards.Basic Usage
Basic Slider
Slider with Label
Slider with Value Display
Slider with Divisions
Disabled Slider
Properties
Core Properties
value- Current slider value (double)onChanged- Callback triggered when value changes (null for disabled)min- Minimum value (default: 0.0)max- Maximum value (default: 100.0)
Display Properties
label- Optional label displayed above the slidershowValue- Whether to display the current value next to the labeldivisions- Number of discrete divisions (null for continuous)
Styling Properties
size- Slider size variant (small, medium, large)activeColor- Custom active color (uses primary color by default)isDisabled- Whether the slider is disabled
Size Variants
Small Slider
- Track Height: 2px
- Thumb Size: 14px × 14px
- Overlay Size: 28px × 28px
- Tick Size: 2px
Medium Slider ⭐ Default
- Track Height: 3px
- Thumb Size: 18px × 18px
- Overlay Size: 36px × 36px
- Tick Size: 3px
Large Slider
- Track Height: 4px
- Thumb Size: 22px × 22px
- Overlay Size: 44px × 44px
- Tick Size: 4px
Styling & Colors
Slider Colors
- Active Track:
HuxTokens.primary(context)(or customactiveColor) - Inactive Track:
HuxTokens.surfaceSecondary(context) - Thumb:
HuxTokens.primary(context)(or customactiveColor) - Overlay: Primary color with 10% opacity
- Tick Marks:
HuxTokens.primary(context)(when divisions are used)
Disabled State Colors
- Active Track (Disabled):
HuxTokens.borderSecondary(context) - Inactive Track (Disabled):
HuxTokens.surfaceSecondary(context)with 50% opacity - Thumb (Disabled):
HuxTokens.surfaceSecondary(context) - Text (Disabled):
HuxTokens.textDisabled(context)
Custom Colors
You can customize the slider’s active color:Advanced Examples
Volume Control
Rating Slider
Price Range Filter
Form Integration
Accessibility
HuxSlider follows Flutter’s accessibility guidelines:- Supports keyboard navigation
- Provides semantic labels for screen readers
- Maintains proper touch target sizes (minimum 44px × 44px)
- Uses theme-aware colors that meet WCAG contrast requirements
Best Practices
- Use Labels: Always provide a label to make the slider’s purpose clear
- Show Values: Use
showValue: truewhen the exact value is important - Use Divisions: Set
divisionswhen you need discrete values (e.g., ratings, steps) - Provide Feedback: Consider showing additional feedback when the value changes (e.g., updating a preview)
- Range Selection: For range selection, use two sliders or consider a RangeSlider component
API Reference
HuxSlider Properties
| Property | Type | Default | Description |
|---|---|---|---|
value | double | — | Current slider value (required) |
onChanged | ValueChanged<double>? | — | Callback when value changes |
min | double | 0.0 | Minimum value |
max | double | 100.0 | Maximum value |
divisions | int? | null | Number of discrete divisions |
label | String? | null | Label displayed above slider |
showValue | bool | false | Whether to show current value |
isDisabled | bool | false | Whether slider is disabled |
size | HuxSliderSize | medium | Size variant |
activeColor | Color? | null | Custom active color |
HuxSliderSize Enum
HuxSliderSize.small- Small slider for compact layoutsHuxSliderSize.medium- Medium slider for standard use (default)HuxSliderSize.large- Large slider for emphasis