avoid_border_all
v0.4.0 Warning Fix Widget Replacement
Flags usages of Border.all() which should be replaced with Border.fromBorderSide(BorderSide(...)). The Border.all() factory delegates to Border.fromBorderSide() internally, but it cannot be made const because it is a factory constructor.
Why use this rule
Section titled “Why use this rule”Border.all() calls Border.fromBorderSide() under the hood, so using Border.fromBorderSide(BorderSide(...)) directly allows the entire expression to be const. Const objects are canonicalized at compile time, which reduces allocations and improves performance — especially in build methods that run frequently.
See also: Border | Dart lint: prefer_const_constructors
// Border.all() cannot be constfinal border1 = Border.all();
// Border.all() with argumentsfinal border2 = Border.all( color: const Color(0xFF3355AA), width: 2.5, style: BorderStyle.solid,);// Border.fromBorderSide() supports constfinal border1 = const Border.fromBorderSide(BorderSide());
final border2 = const Border.fromBorderSide( BorderSide(color: Color(0xFF3355AA), width: 2.5, style: BorderStyle.solid),);Configuration
Section titled “Configuration”This rule is in the opinionated preset, so it is on with
preset: opinionated, or by name:
rules: avoid_border_all: trueTo turn it off again:
rules: avoid_border_all: falseTo keep the rule on but skip certain paths, use per-rule exclude.
Related rules
Section titled “Related rules”prefer_const_border_radius— Use BorderRadius.all(Radius.circular()) for const support.avoid_expanded_as_spacer— Use Spacer instead of Expanded with an empty child.avoid_incorrect_image_opacity— Use Image’s opacity parameter instead of wrapping in Opacity.avoid_wrapping_in_padding— Avoid wrapping widgets that support padding in a Padding widget.