Skip to content

prefer_center_over_align

v0.1.0 Warning Fix Widget Replacement

Flags Align widgets that use Alignment.center (or omit the alignment parameter, which defaults to center). In these cases, the Center widget is a clearer and more idiomatic replacement.

Center is a specialized subclass of Align that always aligns to center. Using Center makes the intent immediately obvious and removes the redundant alignment: Alignment.center argument. If you omit alignment on Align, Flutter defaults to center anyway — so you should just use Center.

See also: Center | Align

// Align with explicit Alignment.center
Align(alignment: Alignment.center, child: Text('Hello'));
// Align without alignment defaults to center
Align(child: Text('World'));
// Use Center directly
Center(child: Text('Hello'));
Center(child: Text('World'));

To disable this rule:

plugins:
many_lints:
diagnostics:
prefer_center_over_align: false