avoid-border-all

Path
lint/performance/avoid-border-all
Default
Off, opt in
Origin
Falcon
Domain
flutter
Rule
26 of 512
flutter

Avoids Flutter's non-const Border.all factory. Use Border.fromBorderSide(const BorderSide(...)) when the side is constant. Only invocations whose arguments can all be constant qualify.

Invalid

example.dartdart
import 'package:flutter/widgets.dart';
import 'package:flutter/widgets.dart' as f;
typedef B = Border;
void callback() {}
void examples(Widget child, dynamic image, dynamic color, double size, String label) {
  Border.all();
  Border.all(width: 2);
  new Border.all();
  f.Border.all(color: 0xff112233);
  B.all(width: 3);
}
Prefer `Border.fromBorderSide` with a `const` `BorderSide` instead of `Border.all`.
5void examples(Widget child, dynamic image, dynamic color, double size, String label) {
6 Border.all();
Prefer `Border.fromBorderSide` with a `const` `BorderSide` instead of `Border.all`.
6 Border.all();
7 Border.all(width: 2);
Prefer `Border.fromBorderSide` with a `const` `BorderSide` instead of `Border.all`.
7 Border.all(width: 2);
8 new Border.all();
Prefer `Border.fromBorderSide` with a `const` `BorderSide` instead of `Border.all`.
8 new Border.all();
9 f.Border.all(color: 0xff112233);
Prefer `Border.fromBorderSide` with a `const` `BorderSide` instead of `Border.all`.
9 f.Border.all(color: 0xff112233);
10 B.all(width: 3);

Valid

example.dartdart
import 'package:flutter/widgets.dart';
import 'package:flutter/widgets.dart' as f;
typedef B = Border;
void callback() {}
void examples(Widget child, dynamic image, dynamic color, double size, String label) {
  const Border();
  const Border.fromBorderSide(BorderSide());
  Border.fromBorderSide(BorderSide(width: 2));
  f.Border();
  const B();
}

Configure avoid-border-all

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

falcon.jsonjson
{
  "linter": {
    "rules": {
      "performance": {
        "avoid-border-all": "error"
      }
    }
  }
}

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

example.dartdart
// falcon-ignore lint/performance/avoid-border-all: <reason>