prefer_const_border_radius
v0.4.0 Warning Fix Widget Replacement
Flags usages of BorderRadius.circular() which should be replaced with BorderRadius.all(Radius.circular(...)). The BorderRadius.circular() factory delegates to BorderRadius.all(Radius.circular()) internally, but it cannot be made const because it is a factory constructor.
Why use this rule
Section titled “Why use this rule”BorderRadius.circular() calls BorderRadius.all(Radius.circular()) under the hood. Using the explicit form allows the entire expression to be const, which means the Dart compiler can canonicalize it at compile time. This avoids repeated allocations in build methods and is especially beneficial for border radii that never change.
See also: BorderRadius | Dart lint: prefer_const_constructors
// BorderRadius.circular cannot be constfinal radius = BorderRadius.circular(8);
final radius2 = BorderRadius.circular(16.0);// BorderRadius.all(Radius.circular()) supports constfinal radius = BorderRadius.all(Radius.circular(8));
const radius2 = BorderRadius.all(Radius.circular(16.0));Configuration
Section titled “Configuration”This rule is in the opinionated preset, so it is on with
preset: opinionated, or by name:
rules: prefer_const_border_radius: trueTo turn it off again:
rules: prefer_const_border_radius: falseTo keep the rule on but skip certain paths, use per-rule exclude.
Related rules
Section titled “Related rules”avoid_border_all— Use Border.fromBorderSide instead of Border.all 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.