Last active
August 11, 2020 12:42
-
-
Save AnkitChowdhury/ac79cbf8e16a919fa174e20ab183f576 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
class CustomSliderThumbRect extends SliderComponentShape { | |
final double thumbRadius; | |
final thumbHeight; | |
final int min; | |
final int max; | |
const CustomSliderThumbRect({ | |
this.thumbRadius, | |
this.thumbHeight, | |
this.min, | |
this.max, | |
}); | |
@override | |
Size getPreferredSize(bool isEnabled, bool isDiscrete) { | |
return Size.fromRadius(thumbRadius); | |
} | |
@override | |
void paint( | |
PaintingContext context, | |
Offset center, { | |
Animation<double> activationAnimation, | |
Animation<double> enableAnimation, | |
bool isDiscrete, | |
TextPainter labelPainter, | |
RenderBox parentBox, | |
SliderThemeData sliderTheme, | |
TextDirection textDirection, | |
double value, | |
double textScaleFactor, | |
Size sizeWithOverflow, | |
}) { | |
final Canvas canvas = context.canvas; | |
final rRect = RRect.fromRectAndRadius( | |
Rect.fromCenter( | |
center: center, width: thumbHeight * 1.2, height: thumbHeight * .6), | |
Radius.circular(thumbRadius * .4), | |
); | |
final paint = Paint() | |
..color = sliderTheme.activeTrackColor //Thumb Background Color | |
..style = PaintingStyle.fill; | |
TextSpan span = new TextSpan( | |
style: new TextStyle( | |
fontSize: thumbHeight * .3, | |
fontWeight: FontWeight.w700, | |
color: sliderTheme.thumbColor, | |
height: 1), | |
text: '${getValue(value)}'); | |
TextPainter tp = new TextPainter( | |
text: span, | |
textAlign: TextAlign.left, | |
textDirection: TextDirection.ltr); | |
tp.layout(); | |
Offset textCenter = | |
Offset(center.dx - (tp.width / 2), center.dy - (tp.height / 2)); | |
canvas.drawRRect(rRect, paint); | |
tp.paint(canvas, textCenter); | |
} | |
String getValue(double value) { | |
return (min+(max-min)*value).round().toString(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
still can't understand how to change radius of range slider....
I mean how to use this code