Transform.scale constructor

Transform.scale({
  1. Key? key,
  2. double? scale,
  3. double? scaleX,
  4. double? scaleY,
  5. Offset? origin,
  6. AlignmentGeometry? alignment = Alignment.center,
  7. bool transformHitTests = true,
  8. FilterQuality? filterQuality,
  9. Widget? child,
})

Creates a widget that scales its child along the 2D plane.

The scaleX argument provides the scalar by which to multiply the x axis, and the scaleY argument provides the scalar by which to multiply the y axis. Either may be omitted, in which case the scaling factor for that axis defaults to 1.0.

For convenience, to scale the child uniformly, instead of providing scaleX and scaleY, the scale parameter may be used.

At least one of scale, scaleX, and scaleY must be non-null. If scale is provided, the other two must be null; similarly, if it is not provided, one of the other two must be provided.

The alignment controls the origin of the scale; by default, this is the center of the box.

This example shrinks an orange box containing text such that each dimension is half the size it would otherwise be.
link
Transform.scale(
  scale: 0.5,
  child: Container(
    padding: const EdgeInsets.all(8.0),
    color: const Color(0xFFE8581C),
    child: const Text('Bad Idea Bears'),
  ),
)

See also:

  • ScaleTransition, which animates changes in scale smoothly over a given duration.

Implementation

Transform.scale({
  super.key,
  double? scale,
  double? scaleX,
  double? scaleY,
  this.origin,
  this.alignment = Alignment.center,
  this.transformHitTests = true,
  this.filterQuality,
  super.child,
})  : assert(!(scale == null && scaleX == null && scaleY == null), "At least one of 'scale', 'scaleX' and 'scaleY' is required to be non-null"),
      assert(scale == null || (scaleX == null && scaleY == null), "If 'scale' is non-null then 'scaleX' and 'scaleY' must be left null"),
      transform = Matrix4.diagonal3Values(scale ?? scaleX ?? 1.0, scale ?? scaleY ?? 1.0, 1.0);