I have a customized RangeSlider with 2 values: RangeValues.start / RangeValues.end.
How to put RangeValues.start in left thumb and RangeValues.end in right thumb?
As you can see value is the same on both thumbs
My CustomRangeSliderThumbShape :
class CustomRangeSliderThumbShape extends RangeSliderThumbShape {
final RangeValues valueSlider;
CustomRangeSliderThumbShape({required this.valueSlider});
@override
Size getPreferredSize(bool isEnabled, bool isDiscrete) {
return const Size.fromRadius(20.0);
}
@override
void paint(
PaintingContext context,
Offset center, {
required Animation<double> activationAnimation,
required Animation<double> enableAnimation,
required SliderThemeData sliderTheme,
bool? isDiscrete,
bool? isEnabled,
bool? isOnTop,
TextDirection? textDirection,
Thumb? thumb,
bool? isPressed,
}) {
final Canvas canvas = context.canvas;
// Draw the outer circle
final outerRadius = 30.0;
final outerPaint = Paint()..color = primaryColor;
canvas.drawCircle(center, outerRadius, outerPaint);
// Draw the inner circle
final innerRadius = 28.0;
final innerPaint = Paint()..color = Colors.white;
canvas.drawCircle(center, innerRadius, innerPaint);
// Draw the text
final textStyle = TextStyle(
color: Colors.black, fontWeight: FontWeight.bold, fontSize: 20);
final textSpan = TextSpan(
text: valueSlider.start.toInt().toString(),
style: textStyle,
);
final textPainter = TextPainter(
text: textSpan,
textDirection: TextDirection.ltr,
);
textPainter.layout();
textPainter.paint(
canvas,
Offset(
center.dx - textPainter.width / 2,
center.dy - textPainter.height / 2,
),
);
}
}
2
Answers
See If you look this below line, it’s responsible of getting the same value in you both the
start
andend
thumbs. So you need to change this.To display different values on the left and right thumbs, you need to pass a condition as thumb is
left
orright
and displaystart
andend
range value accordingly:— try to this code to create left and right thums slider bar in flutter