Flutter: How to adjust the height of a container as the maximum height of its sibling in a row

Viewed 1905

I have two widgets in a row. The first widget is a black line with width 5.0, the second widget is a text widget whose size may vary according to the content. I want the first container to have the same height as of the second widget

2 Answers

One way is to make both widget child of an IntrinsicHeight widget and then declare the height of the first container as double.infinity. This should solve your problem. Example code is given below:

IntrinsicHeight(
  child: Row(
    children: <Widget>[
      Container(  //this is the first container
         height: double.infinity
      ),
      secondWidget(
      )
    ],
)

Let me know if you have further query. Happy coding!

You can use Expanded widget. It divides siblings to the same height or width. here is the code:

Row(
    children: <Widget>[
      Expanded(
        child: Container(
          color: Colors.red,
        ),
      ),
      Expanded(
        child: Container(
          color: Colors.green,
        ),
   )

And here is the result:

enter image description here

That is so easy. I wish it could help.

Related