Skip to content

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.

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 const
final border1 = Border.all();
// Border.all() with arguments
final border2 = Border.all(
color: const Color(0xFF000000),
width: 1.0,
style: BorderStyle.solid,
);
// Border.fromBorderSide() supports const
final border1 = const Border.fromBorderSide(BorderSide());
final border2 = const Border.fromBorderSide(
BorderSide(color: Color(0xFF000000), width: 1.0, style: BorderStyle.solid),
);

To disable this rule:

plugins:
many_lints:
diagnostics:
avoid_border_all: false