Skip to main content

prefer-spacing

Suggests using the spacing argument of a Row, Column or Flex instead of using SizedBox widgets for adding gaps between children widgets.

info

This argument is available only since Flutter 3.27. Enable this rule only if you have already migrated to that (or later) version.

Example

❌ Bad:

// LINT: Prefer passing the 'spacing' argument instead of using the 'SizedBox' widget.
Column(children: [
Widget(),
SizedBox(height: 10),
Widget(),
]);

// LINT: Prefer passing the 'spacing' argument instead of using the 'SizedBox' widget.
Column(
children: [Widget(), Widget()].separatedBy(
const SizedBox(height: 10),
),
);

// LINT: Prefer passing the 'spacing' argument instead of using the 'SizedBox' widget.
Column(
children: widgets
.expand((widget) sync* {
yield const SizedBox(height: 10);
yield widget;
})
.skip(1)
.toList(),
);

✅ Good:

Column(
spacing: 10,
children: [
Widget(),
Widget(),
],
);