Skip to content

avoid_single_child_in_multi_child_widgets

v0.1.0 Warning Fix 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.

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.

See also: Column | Row

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'),
)

To disable this rule:

plugins:
many_lints:
diagnostics:
avoid_single_child_in_multi_child_widgets: false