Skip to content

use_gap

v0.2.0WarningFixConfigurableWidget Best Practices

This rule suggests replacing SizedBox and Padding spacers inside multi-child widgets (Column, Row, etc.) with the Gap widget from the gap package. Gap automatically picks the right axis based on its parent, so you never accidentally use width in a Column or height in a Row.

Using SizedBox(height: 16) for spacing works, but it is error-prone in Row (where you need width instead) and verbose in either case. Gap(16) is axis-aware, shorter, and makes the intent clearer: this is a spacer, not a box with specific dimensions. It also reduces bugs when refactoring a Column to a Row or vice versa.

See also: gap package

final widgets = <Widget>[
Column(
children: const [
Text('First'),
SizedBox(height: 16),
Text('Second'),
],
),
Row(
children: const [
Text('Left'),
SizedBox(width: 8),
Text('Right'),
],
),
];
final widgets = <Widget>[
Column(
children: const [Text('First'), Gap(16), Text('Second')],
),
Row(
children: const [Text('Left'), Gap(8), Text('Right')],
),
];

This rule is in no preset, so it is off unless you enable it by name:

many_lints.yaml
rules:
use_gap: true

To turn it off again:

many_lints.yaml
rules:
use_gap: false

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

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