avoid-single-child-column-or-row

Same as avoid_single_child_column_or_row in Pyramid Lint

Group
Style
Path
lint/style/avoid-single-child-column-or-row
Default
Off, opt in
Origin
Pyramid Lint
Domain
flutter
Rule
141 of 512
flutter

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>[];

Configure avoid-single-child-column-or-row

Set its severity in falcon.json. See the configuration guide.

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

Or silence one occurrence with a suppression comment; the reason is required.

example.dartdart
// falcon-ignore lint/style/avoid-single-child-column-or-row: <reason>