Skip to main content

avoid-border-all

added in: 1.6.0
🛠
Free+

Suggests replacing the Border.all constructor with the const Border.fromBorderSide constructor.

Border.all constructor calls const Border.fromBorderSide constructor under the hood and can be safely replaced by it.

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: This constructor can be replaced with a const constructor 'Border.fromBorderSide'.
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: Color(0xFF000000),
width: 1.0,
style: BorderStyle.solid,
)),
child: child,
);
}
}