sized_box_shrink_expand

Group: style

Maturity: stable

Dart SDK: >= 2.16.0 • (Linter v1.15.0)

Since info is static, may be stale

View all Lint Rules

Using the Linter

Use SizedBox.shrink(...) and SizedBox.expand(...) constructors appropriately.

The SizedBox.shrink(...) and SizedBox.expand(...) constructors should be used instead of the more general SizedBox(...) constructor when the named constructors capture the intent of the code more succinctly.

Examples

BAD:

Widget buildLogo() {
  return SizedBox(
    height: 0,
    width: 0,
    child: const MyLogo(),
  );
}
Widget buildLogo() {
  return SizedBox(
    height: double.infinity,
    width: double.infinity,
    child: const MyLogo(),
  );
}

GOOD:

Widget buildLogo() {
  return SizedBox.shrink(
    child: const MyLogo(),
  );
}
Widget buildLogo() {
  return SizedBox.expand(
    child: const MyLogo(),
  );
}

Usage

To enable the sized_box_shrink_expand lint, add sized_box_shrink_expand under linter > rules in your analysis_options.yaml file:

linter:
  rules:
    - sized_box_shrink_expand