6

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.

Petr Klein
  • 797
  • 2
  • 9
  • 23

1 Answers1

6

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.

Siavash
  • 3,242
  • 3
  • 16
  • 18
  • Thank you, but I used Container for use paddings, I will try put Container inside Expanded. I have one more question and what is different between Flexible vs Expanded – Petr Klein Jun 14 '18 at 14:24
  • Unlike Expanded, Flexible does not require the child to fill the available space : https://docs.flutter.io/flutter/widgets/Flexible-class.html – Siavash Jun 14 '18 at 14:54