draw method
void
draw(})
Implementation
void draw(
ui.Canvas canvas,
ui.Rect rect, {
BoxFit? fit,
Alignment? alignment,
RenderCacheContext? renderCache,
}) {
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);
_matrix.setIdentity();
var cacheUsed = false;
if (renderCache != null) {
var progressForCache = _progressAliases[progress] ?? progress;
cacheUsed = renderCache.cache.draw(
this,
progressForCache,
canvas,
destinationPosition: destinationPosition,
destinationRect: destinationRect,
sourceSize: sourceSize,
sourceRect: sourceRect,
renderBox: renderCache.renderBox,
devicePixelRatio: renderCache.devicePixelRatio,
);
}
if (!cacheUsed) {
canvas.save();
canvas.translate(destinationRect.left, destinationRect.top);
_matrix.scale(destinationSize.width / sourceRect.width,
destinationSize.height / sourceRect.height);
_compositionLayer.draw(canvas, _matrix, parentAlpha: 255);
canvas.restore();
}
}