Skip to content

Files

Latest commit

 

History

History
51 lines (41 loc) · 977 Bytes

sized_box_shrink_expand.md

File metadata and controls

51 lines (41 loc) · 977 Bytes

Pattern: Use of SizedBox(...) constructor

Issue: -

Description

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.

Example of incorrect code:

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

Example of correct code:

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

Further Reading