Skip to content

Instantly share code, notes, and snippets.

@yc-codes
Created January 3, 2022 06:18
Show Gist options
  • Save yc-codes/cb6be7142b748c0e8a8bf6c72c24b65b to your computer and use it in GitHub Desktop.
Save yc-codes/cb6be7142b748c0e8a8bf6c72c24b65b to your computer and use it in GitHub Desktop.
Dashed arrow - Custom painter - flutter - dart
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;
}
}
}
@yc-codes
Copy link
Author

yc-codes commented Jan 3, 2022

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment