prefer_align_over_container
v0.1.0 Warning Fix Widget Replacement
Flags Container widgets that only use the alignment parameter (plus optional key and child). When Container is used solely for alignment, the Align 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 alignment, using Align directly avoids the overhead and makes the intent clearer. It also makes the widget tree easier to understand at a glance.
// Container with only alignment parameterContainer(alignment: Alignment.topLeft, child: Text('Hello'));
// Container with only alignment, no childContainer(alignment: Alignment.bottomRight);// Use Align directlyAlign(alignment: Alignment.topLeft, child: Text('Hello'));
Align(alignment: Alignment.bottomRight);Configuration
Section titled “Configuration”This rule is in the opinionated preset, so it is on with
preset: opinionated, or by name:
rules: prefer_align_over_container: trueTo turn it off again:
rules: prefer_align_over_container: falseTo keep the rule on but skip certain paths, use per-rule exclude.
Related rules
Section titled “Related rules”prefer_container— Opposing convention. Replace sequences of nested widgets with a single Container.prefer_constrained_box_over_container— Use ConstrainedBox instead of Container when only constraints is set.prefer_padding_over_container— Use Padding instead of Container when only padding or margin is set.prefer_transform_over_container— Use Transform instead of Container when only transform is set.