56 lines
1.4 KiB
Dart
56 lines
1.4 KiB
Dart
// Author: fengshengxiong
|
|
// Date: 2024/6/2
|
|
// Description: 自定义RoundRectSliderThumbShape
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
class RoundRectSliderThumbShape extends SliderComponentShape {
|
|
final double thumbHeight;
|
|
final double thumbWidth;
|
|
final double thumbRadius;
|
|
final Color thumbColor;
|
|
|
|
const RoundRectSliderThumbShape({
|
|
this.thumbHeight = 20.0,
|
|
this.thumbWidth = 20.0,
|
|
this.thumbRadius = 6.0,
|
|
this.thumbColor = Colors.black,
|
|
});
|
|
|
|
@override
|
|
Size getPreferredSize(bool isEnabled, bool isDiscrete) {
|
|
return Size(thumbWidth, thumbHeight);
|
|
}
|
|
|
|
@override
|
|
void paint(PaintingContext context, Offset center,
|
|
{required Animation<double> activationAnimation,
|
|
required Animation<double> enableAnimation,
|
|
required bool isDiscrete,
|
|
required TextPainter labelPainter,
|
|
required RenderBox parentBox,
|
|
required SliderThemeData sliderTheme,
|
|
required TextDirection textDirection,
|
|
required double value,
|
|
required double textScaleFactor,
|
|
required Size sizeWithOverflow}) {
|
|
|
|
final Paint thumbPaint = Paint()
|
|
..color = thumbColor
|
|
..style = PaintingStyle.fill;
|
|
|
|
final Rect thumbRect = Rect.fromCenter(
|
|
center: center,
|
|
width: thumbWidth,
|
|
height: thumbHeight,
|
|
);
|
|
|
|
final RRect thumbRRect = RRect.fromRectAndRadius(
|
|
thumbRect,
|
|
Radius.circular(thumbRadius),
|
|
);
|
|
|
|
context.canvas.drawRRect(thumbRRect, thumbPaint);
|
|
}
|
|
}
|