avoid-single-child-column-or-row
Warns when a Column
, Row
, Flex
, Wrap
, SliverList
, SliverMainAxisGroup
or SliverCrossAxisGroup
widget has only one child.
A Column
or Row
widget with only one child is usually a sign of a mistake. If you want to center the child widget, prefer the Center
widget instead.
Example
❌ Bad:
Widget build(BuildContext context) {
// LINT: Avoid 'Row' widgets with only one child. Try using a dedicated widget instead.
return Row(children: [
SomeWidget(),
]);
}
✅ Good:
Widget build(BuildContext context) {
return Row(children: [
SomeWidget(),
SomeWidget(),
]);
}
Widget build(BuildContext context) {
return Center(child: SomeWidget());
}