Skip to content

prefer_spacing

v0.4.0 Warning Fix Widget Best Practices

This rule detects SizedBox widgets used as uniform spacers between children in a Row, Column, or Flex, and suggests using the built-in spacing argument instead. It also catches separatedBy() and .expand() patterns that insert SizedBox spacers. Requires Flutter 3.27+.

Scattering SizedBox(height: 10) between every child is verbose and easy to get wrong (miss one, use a different value, etc.). The spacing parameter on Row, Column, and Flex applies uniform spacing declaratively with a single property, making the intent clear and the code shorter. It also avoids polluting the children list with non-semantic spacer widgets.

See also: Column spacing

Column(
children: [
Text('First'),
SizedBox(height: 10),
Text('Second'),
SizedBox(height: 10),
Text('Third'),
],
)
Column(
spacing: 10,
children: [Text('First'), Text('Second'), Text('Third')],
)

To disable this rule:

plugins:
many_lints:
diagnostics:
prefer_spacing: false