draw method
Draws the contents or children of this Drawable to the canvas
, using
the parentPaint
to optionally override the child's paint.
The bounds
specify the area to draw in.
Implementation
@override
void draw(Canvas canvas, Rect bounds) {
if (!hasDrawableContent) {
return;
}
final Function innerDraw = () {
if (style!.groupOpacity == 0) {
return;
}
if (transform != null) {
canvas.save();
canvas.transform(transform!);
}
bool needsSaveLayer = style!.mask != null;
final Paint blendingPaint = Paint();
if (style!.groupOpacity != null && style!.groupOpacity != 1.0) {
blendingPaint.color = Color.fromRGBO(0, 0, 0, style!.groupOpacity!);
needsSaveLayer = true;
}
if (style!.blendMode != null) {
blendingPaint.blendMode = style!.blendMode!;
needsSaveLayer = true;
}
if (needsSaveLayer) {
canvas.saveLayer(null, blendingPaint);
}
for (Drawable child in children!) {
child.draw(canvas, bounds);
}
if (style!.mask != null) {
canvas.saveLayer(null, _grayscaleDstInPaint);
style!.mask!.draw(canvas, bounds);
canvas.restore();
}
if (needsSaveLayer) {
canvas.restore();
}
if (transform != null) {
canvas.restore();
}
};
if (style?.clipPath?.isNotEmpty == true) {
for (Path clipPath in style!.clipPath!) {
if (transform != null) {
clipPath = clipPath.transform(transform!);
}
canvas.save();
canvas.clipPath(clipPath);
if (children!.length > 1) {
canvas.saveLayer(null, Paint());
}
innerDraw();
if (children!.length > 1) {
canvas.restore();
}
canvas.restore();
}
} else {
innerDraw();
}
}