Skip to main content

prefer-constrained-box-over-container

effort: 2m
has auto-fix
teams+

Suggests using the ConstrainedBox widget instead of the Container widget with only the constraints argument.

Example

❌ Bad:

class SomeWidget {
Widget build() {
// LINT: Prefer 'ConstrainedBox' over 'Container' with only the 'constraints' argument.
Container(constraints: BoxConstraints(), child: Widget());
}
}

✅ Good:

class SomeWidget {
Widget build() {
ConstrainedBox(constraints: BoxConstraints(), child: Widget());
Container(
margin: EdgeInsetsGeometry.left,
constraints: BoxConstraints(),
child: Widget(),
);
}
}