如何在Flutter中自定义我的Slider小部件的拇指颜色?

问题描述 投票:0回答:3

我想更改小部件的圆形部分的颜色。此颜色应与activeColorinactiveColor颜色不同。这是我当前的代码:

Slider(
  value: sliderValue.toDouble(),
  max: 100.0,
  min: 0.0,
  activeColor: Colors.red,
  inactiveColor: Colors.grey,
  onChanged: (double newValue) {
    setState(() {
      sliderValue = newValue.round();
    });
  },
),

下面是结果的滑块:

enter image description here

这是我的目标:

enter image description here

请帮助。

flutter slider themes
3个回答
0
投票

您要更改的部分由SliderTheme控制>

您可以在文档中阅读整个部分:https://api.flutter.dev/flutter/material/SliderThemeData-class.html

只需根据您的需要设置值。

SliderTheme(
    data: SliderThemeData(
            thumbColor: Colors.red,
            thumbShape: RoundSliderThumbShape(enabledThumbRadius: 20)),
    child: Slider(
          ...
          },
        ),
      ),

并且您的活动颜色为Colors.white


0
投票

您可以在下面复制粘贴运行完整代码您可以使用SliderTheme并设置activeTrackColorinactiveTrackColor


0
投票

用SliderTheme包装

© www.soinside.com 2019 - 2024. All rights reserved.