Skip to content

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.

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.

See also: Align | Container

// Container with only alignment parameter
Container(alignment: Alignment.topLeft, child: Text('Hello'));
// Container with only alignment, no child
Container(alignment: Alignment.bottomRight);
// Use Align directly
Align(alignment: Alignment.topLeft, child: Text('Hello'));
Align(alignment: Alignment.bottomRight);

To disable this rule:

plugins:
many_lints:
diagnostics:
prefer_align_over_container: false