Skip to content

prefer_spacing

v0.4.0WarningConfigurableWidget 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')],
)

This rule is in the opinionated preset, so it is on with preset: opinionated, or by name:

many_lints.yaml
rules:
prefer_spacing: true

To turn it off again:

many_lints.yaml
rules:
prefer_spacing: false

To keep the rule on but skip certain paths, use per-rule exclude.

analysis_options.yaml
many_lints:
rules:
prefer_spacing:
min_children: 5
Option Type Default Description
min_children int 3 Minimum number of children in the list before spacers are reported