prefer_sized_box_square
v0.4.0 Warning Fix Widget Replacement
Flags SizedBox constructors where width and height are set to the same value. Flutter provides SizedBox.square(dimension: ...) as a cleaner way to express this intent.
Why use this rule
Section titled “Why use this rule”When width and height are identical, SizedBox.square communicates “this is a square” at a glance, whereas SizedBox(width: 50, height: 50) requires the reader to compare both values. The named constructor eliminates duplication and makes the code more self-documenting.
See also: SizedBox.square
// Both width and height are the same literalSizedBox(width: 10, height: 10);
// Same double literalSizedBox(width: 24.0, height: 24.0);
// Same variable referenceconst size = 48.0;SizedBox(width: size, height: size);
// With a child widgetSizedBox(width: 50, height: 50, child: Text('Hello'));// Use SizedBox.squareSizedBox.square(dimension: 10);
// Different width and height is fineSizedBox(width: 100, height: 50);
// Only width specifiedSizedBox(width: 10);
// Only height specifiedSizedBox(height: 10);Configuration
Section titled “Configuration”To disable this rule:
plugins: many_lints: diagnostics: prefer_sized_box_square: false