incorrect use of parent data widget. expanded widgets must be placed inside flex widgets

Solution 1:

Expanded cannot be used inside a Stack.

You should use Expanded only within a Column, Row or Flex

Solution 2:

What does the error meaning

This error is about missing an expected parent widget.

In this case just removing Expanded or wrapping it in a Column should fix the problem.

While Flutter’s widgets are generally flexible in how they can be composed together in a UI, a small subset of those widgets expect specific parent widgets. When this expectation can’t be satisfied in your widget tree, you’re likely to see this error.

Here is an incomplete list of widgets that expect specific parent widgets within the Flutter framework. Feel free to submit a PR (using the doc icon in the top right corner of the page) to expand this list.

|              Widget                       |    Expected parent widget(s)    |
| ---------------------------------------   | ------------------------------- |
|         Flexible                          |         Row, Column, or Flex    |
|         Expanded (a specialized Flexible) |         Row, Column, or Flex    |
|         Positioned                        |         Stack                   |
|         TableCell                         |         Table                   |

To fix it

The fix should be obvious once you know which parent widget is missing.

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!

Solution 3:

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

Solution 4:

there are may things to get this problem

  1. Under ListView don't use Spacer Widget
  2. don't use Positioned under Row or Column
  3. Expanded can only use it must be a descendant of Column Row Flex