Skip to main content

avoid-border-all

added in: 1.6.0
performance
🛠

Border.all constructor calls const Border.fromBorderSide constructor under the hood. This rule allows to replace Border.all with const Border.fromBorderSide.

Example

❌ Bad:

class BorderWidget extends StatelessWidget {
final Widget child;

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


Widget build(BuildContext context) {
return Container(
//LINT
border: Border.all(
color: const Color(0xFF000000),
width: 1.0,
style: BorderStyle.solid,
),
child: child,
);
}
}

✅ Good:

class BorderWidget extends StatelessWidget {
final Widget child;

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


Widget build(BuildContext context) {
return Container(
border: const Border.fromBorderSide(BorderSide(
color: const Color(0xFF000000),
width: 1.0,
style: BorderStyle.solid,
)),
child: child,
);
}
}