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.
Why use this rule
Section titled “Why use this rule”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.
// Align with explicit Alignment.centerAlign(alignment: Alignment.center, child: Text('Hello'));
// Align without alignment defaults to centerAlign(child: Text('World'));// Use Center directlyCenter(child: Text('Hello'));
Center(child: Text('World'));Configuration
Section titled “Configuration”This rule is in the opinionated preset, so it is on with
preset: opinionated, or by name:
rules: prefer_center_over_align: trueTo turn it off again:
rules: prefer_center_over_align: falseTo keep the rule on but skip certain paths, use per-rule exclude.
Related rules
Section titled “Related rules”prefer_sized_box_square— Use SizedBox.square when width and height are equal.prefer_text_rich— Use Text.rich instead of RichText for better accessibility.prefer_align_over_container— Use Align instead of Container when only alignment is set.avoid_border_all— Use Border.fromBorderSide instead of Border.all for const support.