prefer_transform_over_container
v0.4.0 Warning Fix Widget Replacement
Flags Container widgets that only use the transform parameter (plus optional key and child). When Container is used solely for a transform, the Transform widget is a lighter, more descriptive alternative.
Why use this rule
Section titled “Why use this rule”Container is a convenience widget that composes many lower-level widgets internally. When you only need a matrix transform, using Transform directly avoids the overhead and clearly communicates your intent. It also gives you access to Transform’s named constructors like Transform.rotate and Transform.scale.
See also: Transform | Container
// Container with only transform parameterContainer( transform: Matrix4.skewY(0.3)..rotateZ(-math.pi / 12.0), child: const Text('Skewed'),);
// Container with only transform and keyContainer( key: const ValueKey('rotated'), transform: Matrix4.rotationZ(math.pi / 4), child: const Text('Rotated'),);// Use Transform directlyTransform( transform: Matrix4.skewY(0.3)..rotateZ(-math.pi / 12.0), child: const Text('Skewed'),);
// Container with transform and other parameters is fineContainer( transform: Matrix4.rotationZ(math.pi / 4), alignment: Alignment.topRight, child: const Text('Rotated with alignment'),);Configuration
Section titled “Configuration”To disable this rule:
plugins: many_lints: diagnostics: prefer_transform_over_container: false