paintWithPattern method
After clipping the canvas to the shape we want, paint the Pattern on the rectangle
defined by the provided x
, y
, width
, height
.
Implementation
void paintWithPattern(
Canvas canvas, double x, double y, double width, double height) {
final stripesCount = featuresCount * 2;
var stripeW = width / stripesCount / 1.5;
final paint = Paint()
..style = PaintingStyle.fill
..color = bgColor;
canvas.drawRect(Rect.fromLTWH(x, y, width, height), paint);
var dx = 0.0;
final rectsPath = Path();
for (var i = 1; i < stripesCount; i += 2) {
// Start the pattern from half a background stripe width.
final rect = Rect.fromLTWH(x + dx + stripeW, y, stripeW, height);
rectsPath.addRect(rect);
dx += stripeW * 3;
}
paint
..style = PaintingStyle.fill
..color = fgColor;
canvas.drawPath(rectsPath, paint);
}