Flutter column auto height by parent row

2019-08-09 04:55发布

问题:

I try use Column auto height but still not working.

Example

  • Card

    • Row

      • Expanded(flex:4)

        • NetworkImage (this image has height 120)
      • Expanded(flex: 4)

        • Container
          • Column (this is column what I need)

So I found solution that I have to use Expanded widget so I tried it and got exception

  • Card

    • Row

      • Expanded(flex: 4)

        • NetworkImage (this image has height 120)
      • Expanded(flex: 4)

        • Container
          • Expanded
            • Column (this is column what I need)

Expanded widgets must be placed directly inside Flex widgets. I/flutter (14383): Expanded(no depth, flex: 1, dirty) has a Flex ancestor, but there are other widgets between them: I/flutter (14383): - Expanded(flex: 4) (this is a different Expanded than the one with the problem) I/flutter (14383): These widgets cannot come between a Expanded and its Flex.

Thanks for help.

回答1:

That should be because of the fact that you are adding one of those Expanded widgets to a Container.

An Expanded widget must be a descendant of a Row, Column, or Flex, and the path from the Expanded widget to its enclosing Row, Column, or Flex must contain only StatelessWidgets or StatefulWidgets (not other kinds of widgets, like RenderObjectWidgets).

Replacing the container with a Column should fix it.