Skip to main content

prefer-align-over-container

has auto-fix
pro+

Suggests using the Align widget instead of the Container widget with only the alignment argument.

Example

❌ Bad:

class SomeWidget {
Widget build() {
// LINT: Prefer 'Align' over 'Container' with only the 'alignment' argument.
Container(alignment: Alignment.topRight, child: Widget());
}
}

✅ Good:

class SomeWidget {
Widget build() {
Align(
alignment: Alignment.topRight,
child: Widget(),
);
Container(
transform: Matrix4.skewY(0.3)..rotateZ(-math.pi / 12.0),
alignment: Alignment.topRight,
child: Widget(),
);
}
}