prefer-sized-box-square

Group
Style
Path
lint/style/prefer-sized-box-square
Default
Off, opt in
Origin
Falcon
Domain
flutter
Rule
407 of 512
flutter

Prefers SizedBox.square for an unnamed Flutter SizedBox whose explicit width and height are stable variable reads or numeric literals with identical token spelling. Calls, getters, indexing, missing/null dimensions and existing named constructors are excluded. No automatic fix is offered.

Invalid

example.dartdart
import 'package:flutter/widgets.dart';
import 'package:flutter/widgets.dart' as f;
typedef S = SizedBox;
void callback() {}
void examples(Widget child, dynamic image, dynamic color, double size, String label) {
  SizedBox(width: 10, height: 10);
  const SizedBox(width: 20, height: 20);
  new SizedBox(width: size, height: size);
  f.SizedBox(width: 2.5, height: 2.5);
  S(width: 4, height: 4, child: child);
}
Use `SizedBox.square` when `width` and `height` are the same.
5void examples(Widget child, dynamic image, dynamic color, double size, String label) {
6 SizedBox(width: 10, height: 10);
Use `SizedBox.square` when `width` and `height` are the same.
6 SizedBox(width: 10, height: 10);
7 const SizedBox(width: 20, height: 20);
Use `SizedBox.square` when `width` and `height` are the same.
7 const SizedBox(width: 20, height: 20);
8 new SizedBox(width: size, height: size);
Use `SizedBox.square` when `width` and `height` are the same.
8 new SizedBox(width: size, height: size);
9 f.SizedBox(width: 2.5, height: 2.5);
Use `SizedBox.square` when `width` and `height` are the same.
9 f.SizedBox(width: 2.5, height: 2.5);
10 S(width: 4, height: 4, child: child);

Valid

example.dartdart
import 'package:flutter/widgets.dart';
import 'package:flutter/widgets.dart' as f;
typedef S = SizedBox;
void callback() {}
void examples(Widget child, dynamic image, dynamic color, double size, String label) {
  SizedBox(width: 10, height: 20);
  SizedBox(width: 10);
  SizedBox(height: 10);
  SizedBox(width: null, height: null);
  SizedBox.square(dimension: 10);
}

Configure prefer-sized-box-square

Set its severity in falcon.json. See the configuration guide.

falcon.jsonjson
{
  "linter": {
    "rules": {
      "style": {
        "prefer-sized-box-square": "error"
      }
    }
  }
}

Or silence one occurrence with a suppression comment; the reason is required.

example.dartdart
// falcon-ignore lint/style/prefer-sized-box-square: <reason>