draw method
Implementation
void draw(ui.Canvas canvas, ui.Rect rect,
{BoxFit? fit, Alignment? alignment}) {
if (rect.isEmpty) {
return;
}
fit ??= BoxFit.scaleDown;
alignment ??= Alignment.center;
var outputSize = rect.size;
var inputSize = size;
var fittedSizes = applyBoxFit(fit, inputSize, outputSize);
var sourceSize = fittedSizes.source;
var destinationSize = fittedSizes.destination;
var halfWidthDelta = (outputSize.width - destinationSize.width) / 2.0;
var halfHeightDelta = (outputSize.height - destinationSize.height) / 2.0;
var dx = halfWidthDelta + alignment.x * halfWidthDelta;
var dy = halfHeightDelta + alignment.y * halfHeightDelta;
var destinationPosition = rect.topLeft.translate(dx, dy);
var destinationRect = destinationPosition & destinationSize;
var sourceRect = alignment.inscribe(sourceSize, Offset.zero & inputSize);
canvas.save();
canvas.translate(destinationRect.left, destinationRect.top);
_matrix.setIdentity();
_matrix.scale(destinationRect.size.width / sourceRect.width,
destinationRect.size.height / sourceRect.height);
_compositionLayer.draw(canvas, rect.size, _matrix, parentAlpha: 255);
canvas.restore();
}