Skip to main content

Avoid using Border.all constructor

Has auto-fix

Rule id

avoid-border-all

Severity

Performance

Description

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,
);
}
}