prefer-const-border-radius
added in: 1.0.0performance
BorderRadius.circular
constructor calls const BorderRadius.all
constructor under the hood. This rule allows to replace BorderRadius.circular(value)
with const BorderRadius.all(Radius.circular(value))
if radius is a constant value.
Example
Bad:
final _defaultFinalRadius = BorderRadius.circular(8); // LINT
class RoundedWidget extends StatelessWidget {
final BorderRadius borderRadius;
final Widget child;
const RoundedWidget({
Key? key,
this.borderRadius = _defaultRadius,
required this.child,
}) : super(key: key);
@override
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);
@override
Widget build(BuildContext context) {
return ClipRRect(
borderRadius: borderRadius,
child: child,
);
}
}