Skip to content
On this page

Slider 滑块

代码演示

基本用法

dart
Slider(
  onChangeEnd: (v) {
    ToastStatic.show(context, message: "Value: $v");
    model.value = v;
  },
  value: model.value,
),

步进取整

dart
Slider(
  onChangeEnd: (v) {
    ToastStatic.show(context, message: "Value: $v");
    model.value = v;
  },
  min: 0,
  max: 100,
  step: 1,
  value: model.value,
),

自定义样式

dart
Slider(
  onChangeEnd: (v) => model.value = v,
  min: 0,
  max: 21,
  step: 3,
  value: model.value,
  barHeight: 4,
  activeBg: const Color(0xFFDA3231),
),

自定义按钮

dart
Slider(
  onChangeEnd: (v) => model.value = v,
  min: 0,
  max: 1000,
  step: 1,
  value: model.value,
  drawThumb: (v) => Transform.translate(
    offset: const Offset(-20, 0),
    child: TailBox()
        .bg(const Color(0xFF1989fa))
        .rounded_lg()
        .p(3)
        .Container(
          width: 40,
          height: 20,
          child: FittedBox(
            child: TailTypo().text_color(Colors.white).Text("$v"),
          ),
        ),
  ),
),

API

Props类型描述
valuedouble当前值
onChangeFunction(double)值变化触发
mindouble最小值
maxdouble最大值
stepdouble步进
onChangeEndFunction(double)拖动结束触发
drawThumbWidget Function(double)绘制滑块
activeBgColor选中部分背景颜色
inactiveBgColor未选中部分背景颜色
barHeightdouble滑条高度