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 stripeH = height / stripesCount / 1.5;
final paint = Paint()
..style = PaintingStyle.fill
..color = bgColor;
canvas.drawRect(Rect.fromLTWH(x, y, width, height), paint);
var dy = 0.0;
final rectsPath = Path();
for (var i = 1; i < stripesCount; i += 2) {
// Start the pattern from half a background stripe height.
final rect = Rect.fromLTWH(x, y + dy + stripeH, width, stripeH);
rectsPath.addRect(rect);
dy += stripeH * 3;
}
paint
..style = PaintingStyle.fill
..color = fgColor;
canvas.drawPath(rectsPath, paint);
}