Rules / Style / avoid-single-child-column-or-row

avoid-single-child-column-or-row

lint/style/avoid-single-child-column-or-row
recommendedflutter
Same as avoid_single_child_column_or_row · Pyramid Lint

Flags a Column, Row, or Flex widget built with a single child.

A multi-child layout widget that wraps exactly one child adds a layout node and an allocation without changing what is rendered; the child can be used directly, or swapped for Align, Center, or Padding if the axis behavior actually mattered. The rule fires only when the children list holds exactly one expression element, and it tolerates partially-parsed Dart 3 collection elements by requiring a complete, )-terminated construction.

Invalid

example.dartdart
import 'package:flutter/material.dart';

Widget a() => Column(children: [Text('a')]);

Widget b() => Row(children: [Icon(Icons.add)]);

Widget c() =>
    Flex(direction: Axis.vertical, children: [SizedBox()]);

Widget d() => Column(children: [const Divider()]);

Widget e() => const Row(children: [Text('x')]);
Avoid a Column/Row/Flex with a single child; use the child directly.
2
3Widget a() => Column(children: [Text('a')]);
Avoid a Column/Row/Flex with a single child; use the child directly.
4
5Widget b() => Row(children: [Icon(Icons.add)]);
Avoid a Column/Row/Flex with a single child; use the child directly.
7Widget c() =>
8 Flex(direction: Axis.vertical, children: [SizedBox()]);
Avoid a Column/Row/Flex with a single child; use the child directly.
9
10Widget d() => Column(children: [const Divider()]);
Avoid a Column/Row/Flex with a single child; use the child directly.
11
12Widget e() => const Row(children: [Text('x')]);

Valid

example.dartdart
import 'package:flutter/material.dart';

Widget a() => Column(children: [Text('a'), Text('b')]);

Widget b() => Row(children: []);

Widget c() => Column(children: [...items]);

Widget d() => SizedBox(child: Text('a'));

Widget e() =>
    Column(mainAxisSize: MainAxisSize.min, children: [Text('a'), Icon(Icons.add)]);

Widget f() => Wrap(children: [Text('a')]);

const items = <Widget>[];

How to configure

Set the severity of avoid-single-child-column-or-row in your falcon.json:

falcon.jsonjson
{
  "linter": {
    "rules": {
      "style": {
        "avoid-single-child-column-or-row": "error"
      }
    }
  }
}