ScalingTransform constructor
ScalingTransform({})
Implementation
factory ScalingTransform(
{required Size containerSize,
required Rect siViewport,
BoxFit fit = BoxFit.contain,
Alignment alignment = Alignment.center}) {
final double sx;
final double sy;
switch (fit) {
case BoxFit.fill:
sx = containerSize.width / siViewport.width;
sy = containerSize.height / siViewport.height;
break;
case BoxFit.contain:
sx = sy = min(containerSize.width / siViewport.width,
containerSize.height / siViewport.height);
break;
case BoxFit.cover:
sx = sy = max(containerSize.width / siViewport.width,
containerSize.height / siViewport.height);
break;
case BoxFit.fitWidth:
sx = sy = containerSize.width / siViewport.width;
break;
case BoxFit.fitHeight:
sx = sy = containerSize.height / siViewport.height;
break;
case BoxFit.none:
sx = sy = 1;
break;
case BoxFit.scaleDown:
sx = sy = min(
1,
min(containerSize.width / siViewport.width,
containerSize.height / siViewport.height));
break;
}
final extraX = containerSize.width - siViewport.width * sx;
final extraY = containerSize.height - siViewport.height * sy;
final tx = (1 + alignment.x) * extraX / 2;
final ty = (1 + alignment.y) * extraY / 2;
return ScalingTransform._p(sx, sy, tx, ty, siViewport);
}