Skip to main content

prefer-const-border-radius

added in: 1.6.0
🛠
Free+

Suggests replacing the BorderRadius.circular constructor with the const BorderRadius.all constructor.

BorderRadius.circular constructor calls const BorderRadius.all constructor under the hood and can be safely replaced by it.

Example

❌ Bad:

// LINT: Prefer 'const BorderRadius.all' to non-const constructors.
final _defaultFinalRadius = BorderRadius.circular(8);

class RoundedWidget extends StatelessWidget {
final BorderRadius borderRadius;
final Widget child;

const RoundedWidget({
Key? key,
this.borderRadius = _defaultRadius,
required this.child,
}) : super(key: key);


Widget build(BuildContext context) {
return ClipRRect(
borderRadius: borderRadius,
child: child,
);
}
}

✅ Good:

const _defaultRadius = BorderRadius.all(Radius.circular(8));

class RoundedWidget extends StatelessWidget {
final BorderRadius borderRadius;
final Widget child;

const RoundedWidget({
Key? key,
this.borderRadius = _defaultRadius,
required this.child,
}) : super(key: key);


Widget build(BuildContext context) {
return ClipRRect(
borderRadius: borderRadius,
child: child,
);
}
}