paint method
Method to set roundness
Implementation
@override
void paint(Canvas canvas, Size size) {
canvas.translate(contextSize.width, 0.0);
void drawBar(double x, double width) {
final Paint paint = Paint()
..color = backgroundColor
..style = PaintingStyle.fill
..strokeCap = StrokeCap.round;
if (width <= 0) {
return;
}
Rect rect = Rect.fromLTWH(x, 0.0, width, size.height);
switch (circleData ?? CircleData.none) {
case CircleData.none:
canvas.drawRRect(
/// rounded right corner
RRect.fromLTRBAndCorners(
rect.right,
rect.top,
rect.left,
rect.bottom,
bottomRight: const Radius.circular(10),
topRight: const Radius.circular(10),
),
paint,
);
break;
case CircleData.leftCircle:
canvas.drawRRect(
/// rounded left corner
RRect.fromLTRBAndCorners(
rect.right,
rect.top,
rect.left,
rect.bottom,
bottomLeft: const Radius.circular(10),
topLeft: const Radius.circular(10),
),
paint,
);
break;
case CircleData.rightCircle:
canvas.drawRRect(
/// rounded right corner
RRect.fromLTRBAndCorners(
rect.right,
rect.top,
rect.left,
rect.bottom,
bottomRight: const Radius.circular(10),
topRight: const Radius.circular(10),
),
paint,
);
break;
case CircleData.allCircle:
canvas.drawRRect(
/// rounded all corner
RRect.fromLTRBAndCorners(
rect.right,
rect.top,
rect.left,
rect.bottom,
bottomLeft: const Radius.circular(10),
topLeft: const Radius.circular(10),
bottomRight: const Radius.circular(10),
topRight: const Radius.circular(10),
),
paint,
);
break;
}
paintBar(size, canvas, textSpan);
}
/// 0.0 ~ 1.0 * size.width Range specification.
if (value != null) {
drawBar(0.0, (value?.clamp(0.0, 1.0) ?? 0.0) * size.width);
} else {
drawBar(0.0, size.width);
}
}