Flutter 我如何在颤振中制作这样的滑块?

Flutter 我如何在颤振中制作这样的滑块?,flutter,flutter-layout,Flutter,Flutter Layout,您需要覆盖RangeSliderThumbShape以创建自定义拇指形状 RangeSlider( max: 100, min: 0, values: _currentRangeValues, divisions: 100, labels: RangeLabels(


您需要覆盖
RangeSliderThumbShape
以创建自定义拇指形状

               RangeSlider(
                  max: 100,
                  min: 0,
                  values: _currentRangeValues,
                  divisions: 100,
                  labels: RangeLabels(
                    _currentRangeValues.start.round().toString(),
                    _currentRangeValues.end.round().toString(),
                  ),
                  onChanged: (RangeValues values) {
                    setState(() {
                      _currentRangeValues = values;
                    });
                  },
                ),


有关更多信息:

请将图像放在帖子中,而不是图像链接
class CustomThumbShape implements RangeSliderThumbShape {

  const CustomThumbShape({
    this.radius = 15.0,
    this.ringColor = Colors.red,
  });

  /// Outer radius of thumb

  final double radius;

  /// Color of ring

  final Color ringColor;

  @override
  Size getPreferredSize(bool isEnabled, bool isDiscrete) {
    return Size.fromRadius(radius);
  }

  @override
  void paint(PaintingContext context, Offset center,
      {Animation<double> activationAnimation,
      Animation<double> enableAnimation,
      bool isDiscrete,
      bool isEnabled,
      bool isOnTop,
      TextDirection textDirection,
      SliderThemeData sliderTheme,
      Thumb thumb}) {
    final Canvas canvas = context.canvas;

    // To create a ring create outer circle and create an inner cicrle then 
    // subtract inner circle from outer circle and you will get a ring shape
    // fillType = PathFillType.evenOdd will be used for that

    Path path = Path()
      ..addOval(Rect.fromCircle(center: center, radius: radius))
      ..addOval(Rect.fromCircle(center: center, radius: radius - 5))
      ..fillType = PathFillType.evenOdd;

    canvas.drawPath(path, Paint()..color = ringColor);
  }
}

      theme: ThemeData(
        primarySwatch: Colors.blue,
        visualDensity: VisualDensity.adaptivePlatformDensity,
        sliderTheme: SliderThemeData(
          rangeThumbShape: CustomThumbShape(),
        ),
      ),