首页 > 解决方案 > 如何使自定义滑块覆盖颜色与颤动中的拇指颜色不同?

问题描述

我试图在颤振中实现一个自定义滑块 SliderTheme.of(context).copywith(),但是当为拇指及其叠加层分配颜色时,它们都变得相同thumbColor

这是我的结果

实现自定义滑块

我的代码是:

SliderTheme(
    data: SliderTheme.of(context).copyWith(
       activeTrackColor: Colors.white,
      thumbColor: Color(0xffeb1555),
      overlayColor: Color(0x29eb1555),
      thumbShape:
          RoundSliderThumbShape(enabledThumbRadius: 10.0),
      overlayShape:
          RoundSliderThumbShape(enabledThumbRadius: 20.0),
    ),
    child: Slider(
      value: height.toDouble(),
      min: 100.0,
      max: 220.0,
      divisions: 120,
      onChanged: (double newVal) {
        setState(() {
          height = newVal.toInt();
        });
      },
    ),
  ),

欢迎任何帮助。谢谢

标签: flutterdartslider

解决方案


你需要改变

overlayShape: RoundSliderThumbShape(enabledThumbRadius: 20.0),

overlayShape: RoundSliderOverlayShape(overlayRadius: 20.0),

注意 - 它必须是 OVERLAY 形状


推荐阅读