avoid_single_child_in_multi_child_widgets
v0.1.0 Warning Widget Best Practices
This rule flags multi-child widgets like Column, Row, and Wrap that contain only a single child in their children list. A multi-child layout widget with one child adds unnecessary complexity and layout overhead for something that could be expressed more simply.
Why use this rule
Section titled “Why use this rule”A Column or Row with a single child does the same thing as just using that child directly, but adds an extra layout pass and makes the code harder to read. If you need alignment, use Align or Center. If you need padding, use Padding. Using the right widget for the job makes intent clearer and keeps the widget tree lean.
Scaffold( body: Column( // Column with a single child is unnecessary children: [Text('I am the only child')], ),)Scaffold( // Use the child widget directly body: Text('I am the only child'),)Configuration
Section titled “Configuration”This rule is in the opinionated preset, so it is on with
preset: opinionated, or by name:
rules: avoid_single_child_in_multi_child_widgets: trueTo turn it off again:
rules: avoid_single_child_in_multi_child_widgets: falseTo keep the rule on but skip certain paths, use per-rule exclude.
Related rules
Section titled “Related rules”avoid_flexible_outside_flex— Only use Flexible and Expanded as direct children of Row, Column, or Flex.prefer_for_loop_in_children— Prefer collection-for syntax over functional list building in widget children.avoid_returning_widgets— Extract widget helper methods into separate widget classes.avoid_too_many_widgets_per_build— Keep one build method within a widget budget.