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
// Border.all() cannot be constfinal border1 = Border.all();
// Border.all() with argumentsfinal border2 = Border.all( color: const Color(0xFF000000), width: 1.0, style: BorderStyle.solid,);// Border.fromBorderSide() supports constfinal border1 = const Border.fromBorderSide(BorderSide());
final border2 = const Border.fromBorderSide( BorderSide(color: Color(0xFF000000), width: 1.0, style: BorderStyle.solid),);Configuration
Section titled “Configuration”To disable this rule:
plugins: many_lints: diagnostics: avoid_border_all: false