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;
final maxDimension = max(width, height);
final stripeW = maxDimension / stripesCount / 2;
final paint = Paint()
..style = PaintingStyle.fill
..color = bgColor;
canvas.drawRect(Rect.fromLTWH(x, y, width, height), paint);
final rectStripesCount =
stripesCount * 2.5; // to make sure we cover the whole rectangle;
var step = stripeW * 3;
final allStripesPath = Path();
for (var i = 1; i < rectStripesCount; i += 2) {
final stripePath = Path();
stripePath.moveTo(x - stripeW + step, y);
stripePath.lineTo(x + step, y);
stripePath.lineTo(x, y + step);
stripePath.lineTo(x - stripeW, y + step);
stripePath.close();
allStripesPath.addPath(stripePath, Offset.zero);
step += stripeW * 3;
}
paint
..style = PaintingStyle.fill
..color = fgColor;
canvas.drawPath(allStripesPath, paint);
}