Created
February 20, 2025 09:05
-
-
Save BarryDaBee/82cad72b83fb0722d1d0f1351ce9a00f to your computer and use it in GitHub Desktop.
CustomPainter for diagonal stripes. PS: Check the first comment
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
import 'package:flutter/material.dart'; | |
class StripesPainter extends CustomPainter { | |
StripesPainter({required this.stripeColor}); | |
final Color stripeColor; | |
@override | |
void paint(Canvas canvas, Size size) { | |
final paint = Paint() | |
..color = stripeColor | |
..strokeWidth = 10; | |
var stepX = .0; | |
var stepY = size.height; | |
const step = 10; | |
while (stepX < size.width * 2) { | |
canvas.drawLine( | |
Offset(-4, stepY -= step), | |
Offset(stepX += step, size.height + 4), | |
paint, | |
); | |
stepY -= step * 2; | |
stepX += step * 2; | |
} | |
} | |
@override | |
bool shouldRepaint(StripesPainter oldDelegate) => false; | |
} |
Author
BarryDaBee
commented
Feb 20, 2025
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment