Skip to content

avoid_flexible_outside_flex

v0.4.0 Warning Widget Best Practices

This rule flags Flexible and Expanded widgets that are not direct children of a Row, Column, or Flex. These widgets rely on the flex layout protocol to work, so wrapping them inside other widgets like Container or Padding makes them silently do nothing.

When Expanded or Flexible is nested inside a non-flex parent, Flutter does not throw an error at build time — the widget simply has no effect. This leads to confusing layouts where you think you are distributing space but nothing happens. Catching this at lint time saves you from staring at the widget tree wondering why your layout is broken.

See also: Flexible | Row | Column

Column(
children: [
// Expanded is inside a Container, not directly in the Column
Container(child: Expanded(child: Text('hello'))),
// Flexible is inside a Center
Center(child: Flexible(child: Text('hello'))),
],
)
Column(
children: [
// Expanded directly in a Row
Row(children: [Expanded(child: Text('hello'))]),
// Flexible directly in a Column
Flexible(child: Text('hello')),
],
)

To disable this rule:

plugins:
many_lints:
diagnostics:
avoid_flexible_outside_flex: false