render method
Renders the svg on the canvas
using the dimensions provided by size
.
Implementation
void render(
Canvas canvas,
Vector2 size, {
Paint? overridePaint,
}) {
// Scale the canvas to the size of the destination clip bounds
// This is necessary to avoid blurriness when having a
// camera.viewfinder.zoom larger than 1.0
final destinationClipBounds = canvas.getDestinationClipBounds();
final localClipBounds = canvas.getLocalClipBounds();
final widthRatio =
destinationClipBounds.size.width / localClipBounds.size.width;
final heightRatio =
destinationClipBounds.size.height / localClipBounds.size.height;
final localSize = Size(size.x, size.y);
final image = _getImage(localSize, widthRatio, heightRatio);
canvas.save();
canvas.scale(
1 / (pixelRatio * widthRatio),
1 / (pixelRatio * heightRatio),
);
canvas.drawImage(
image,
Offset.zero,
overridePaint ?? _paint,
);
canvas.restore();
}