TransformModifier.scale constructor
- Key? key,
- Widget? child,
- Key? modifierKey,
- double? scale,
- double? scaleX,
- double? scaleY,
- Offset? origin,
- AlignmentGeometry? alignment = Alignment.center,
- bool transformHitTests = true,
- FilterQuality? filterQuality,
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 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.
{@tool snippet}
This example shrinks an orange box containing text such that each dimension is half the size it would otherwise be.
Transform.scale(
scale: 0.5,
child: Container(
padding: const EdgeInsets.all(8.0),
color: const Color(0xFFE8581C),
child: const Text('Bad Idea Bears'),
),
)
{@end-tool}
See also:
- ScaleTransition, which animates changes in scale smoothly over a given duration.
Implementation
TransformModifier.scale({
super.key,
super.child,
super.modifierKey,
double? scale,
double? scaleX,
double? scaleY,
this.origin,
this.alignment = Alignment.center,
this.transformHitTests = true,
this.filterQuality,
}) : 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);