This error occurs when the Child widget has not matched the parent widget.
The Flex widget allows you to control the axis along which the children are placed (horizontal or vertical). This is referred to as the main axis. If you know the main axis in advance, then consider using a Row (if it's horizontal) or Column (if it's vertical) instead, because that will be less verbose.
ParentDataWidget<T extends ParentData> class Null safety. Base class for widgets that hook ParentData information to children of RenderObjectWidgets. This can be used to provide per-child configuration for RenderObjectWidgets with more than one child.
You should use Expanded only within a column, row or flex.
In this case just removing Expanded or wrapping it in a Column should fix the problem.
An Expanded widget must be a descendant of a Row, Column, or Flex
The fix for this above issue, is to move the expanded widget inside a flex widget. Example below.
Row(
children: [
Expanded(
child: Column(
children: [
Container(
padding: EdgeInsets.only(bottom: 8.0),
child: Text(
"Some Lage Somthing",
style: TextStyle(fontWeight: FontWeight.bold),
),
),
Text("Someplace, Country")
],
),
),
Icon(Icons.star)
],
),
);
Happy Fluttering!
First Rule: use Expanded only within a column, row or flex.
Second Rule: Parent column that have expanded child column must be wrapped with expanded as well
there are may things to get this problem
ListView don't use Spacer WidgetPositiond under Row or Column
Expanded can only use it must be a descendant of column row Flex
there's no expanded in my code so i found that using Spacer() too can cause this error if it's inside a listview
In my case, I was using Positioned inside a column. Removing it solved the problem!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With