flexible_outside_flex
Reports a Flexible or Expanded whose parent is a Flutter widget that is not a Row, Column or Flex. Make it a child of a Row, Column or Flex, or remove it and keep its child.
- Tier
- blocking
- Scope
- Flutter
- Lowest preset
- recommended
- Fix
- none
What it reports
Section titled “What it reports”A Flexible, an Expanded or a widget of a class that extends Flexible, written as the child of a Flutter framework widget that lays out its children itself and is not a Flex. The violation is on the name of the Flexible’s constructor.
Such parents are:
Padding,Center,Align,SizedBox,Opacity,Stack,Wrapand every other render object widget of Flutter;- the scrollables
ListView,GridView,CustomScrollViewandSingleChildScrollView.
The parent is the widget whose child argument the Flexible is, or among whose children it is written, also through an if or for element or a conditional expression. A Row, a Column and a Flex are its right parents and are never reported.
The rule is silent in a package that does not use Flutter.
A Flexible hands its child to the Flex it is a child of. Anywhere else, Flutter throws “Incorrect use of ParentDataWidget” when the widget is laid out, and a release build shows a grey box.
The rule reports only where the parent is certain.
Example
Section titled “Example”Padding( padding: const EdgeInsets.all(8), child: Expanded(child: Text(title)),)Row( children: [ Expanded(child: Text(title)), ],)Rule parameters
Section titled “Rule parameters”Set under the assay: key of the project’s root analysis_options.yaml.
| Rule parameter | Default | Effect |
|---|---|---|
enabled |
true |
false switches the rule off for the whole project. |
exclude |
[] |
Path globs where the rule is silent. |
Suppressing it
Section titled “Suppressing it”Write why on the line directly above the suppression:
// Why this place is fine.// ignore: flexible_outside_flex// ignore_for_file: assay/flexible_outside_flex silences it in a whole file, and // ignore: assay/flexible_outside_flex with the prefix works too. See Suppressions.