Last active
April 5, 2020 13:45
-
-
Save divyanshub024/dbae28246a2a5ffd881d4a84bc744981 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
class DashLinePainter extends CustomPainter { | |
final double progress; | |
DashLinePainter({this.progress}); | |
Paint _paint = Paint() | |
..color = Colors.black | |
..strokeWidth = 4.0 | |
..style = PaintingStyle.stroke | |
..strokeJoin = StrokeJoin.round; | |
@override | |
void paint(Canvas canvas, Size size) { | |
var path = Path() | |
..moveTo(0, size.height / 2) | |
..lineTo(size.width * progress, size.height / 2); | |
Path dashPath = Path(); | |
double dashWidth = 10.0; | |
double dashSpace = 5.0; | |
double distance = 0.0; | |
for (PathMetric pathMetric in path.computeMetrics()) { | |
while (distance < pathMetric.length) { | |
dashPath.addPath( | |
pathMetric.extractPath(distance, distance + dashWidth), | |
Offset.zero, | |
); | |
distance += dashWidth; | |
distance += dashSpace; | |
} | |
} | |
canvas.drawPath(dashPath, _paint); | |
} | |
@override | |
bool shouldRepaint(DashLinePainter oldDelegate) { | |
return oldDelegate.progress != progress; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment