Skip to main content

prefer-padding-over-container

added in: 1.24.0
🛠
Pro+

Suggests using a Padding widget instead of the Container widget with only padding or margin arguments.

Example

❌ Bad:

class SomeWidget {
Widget build() {
// LINT: Prefer 'Padding' over 'Container' with only the 'padding' or 'margin' argument.
Container(padding: EdgeInsetsGeometry.left, child: Widget());

// LINT: Prefer 'Padding' over 'Container' with only the 'padding' or 'margin' argument.
Container(margin: EdgeInsetsGeometry.left, child: Widget());
}
}

✅ Good:

class SomeWidget {
Widget build() {
Container(
margin: EdgeInsetsGeometry.left,
alignment: Alignment.first,
child: Widget(),
);
Container(
alignment: Alignment.first,
child: Widget(),
);
}
}