Created
January 3, 2022 06:18
-
-
Save yc-codes/cb6be7142b748c0e8a8bf6c72c24b65b to your computer and use it in GitHub Desktop.
Dashed arrow - Custom painter - flutter - dart
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
class DownArrowPainter extends CustomPainter { | |
@override | |
void paint(Canvas canvas, Size size) { | |
final paint = Paint() | |
..color = Color(0xFFA8BCFF) | |
..strokeCap = StrokeCap.round | |
..strokeWidth = 2; | |
_drawVerticleLine(canvas, paint, size); | |
_drawChevron(canvas, paint, size); | |
} | |
@override | |
bool shouldRepaint(covariant CustomPainter oldDelegate) { | |
return false; | |
} | |
void _drawChevron(Canvas canvas, Paint paint, Size size) { | |
const dashSize = 2.0; | |
const gapSize = 3.0; | |
const chevronHeight = 22.0; | |
var currentY = size.height; | |
var currentX = size.width / 2; | |
while ((currentY - gapSize) > size.height - chevronHeight) { | |
canvas.drawLine( | |
Offset(currentX, currentY), | |
Offset(currentX - dashSize, currentY - dashSize), | |
paint, | |
); | |
currentY -= dashSize + gapSize; | |
currentX -= dashSize + gapSize; | |
} | |
currentY = size.height; | |
currentX = size.width / 2; | |
while ((currentY - gapSize) > size.height - chevronHeight) { | |
canvas.drawLine( | |
Offset(currentX, currentY), | |
Offset(currentX + dashSize, currentY - dashSize), | |
paint, | |
); | |
currentY -= dashSize + gapSize; | |
currentX += dashSize + gapSize; | |
} | |
} | |
void _drawVerticleLine(Canvas canvas, Paint paint, Size size) { | |
const dashSize = 2.0; | |
const gapSize = 4.0; | |
final centerX = size.width / 2; | |
const topOffset = 0; | |
var currentY = 0.0 + topOffset; | |
while ((currentY + gapSize) < size.height) { | |
canvas.drawLine( | |
Offset(centerX, currentY), | |
Offset(centerX, currentY + dashSize), | |
paint, | |
); | |
currentY += dashSize + gapSize; | |
} | |
} | |
} |
Author
yc-codes
commented
Jan 3, 2022
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment