use_gap
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.
Why use this rule
Section titled “Why use this rule”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')], ),];Turning this rule off
Section titled “Turning this rule off”This rule is in no preset, so it is off unless you enable it by name:
rules: use_gap: trueTo turn it off again:
rules: use_gap: falseTo keep the rule on but skip certain paths, use per-rule exclude.
Options
Section titled “Options”many_lints: rules: use_gap: min_children: 3rules: use_gap: min_children: 3| Option | Type | Default | Description |
|---|---|---|---|
min_children |
int | 1 |
Minimum number of children in the list before spacers are reported |
Related rules
Section titled “Related rules”prefer_spacing— Opposing convention. Use the spacing argument on Row/Column instead of SizedBox spacers.avoid_expanded_as_spacer— Use Spacer instead of Expanded with an empty child.always_pass_global_key— Don’t create a GlobalKey inside build.avoid_conditional_hooks— Never call hooks inside conditionals, loops, or ternaries.