简体   繁体   中英

How to set dynamic container height related to it's next container'a height in flutter?

I want my second (blue) container height should match the first (red) container height.

Here is the preview now,

在此处输入图片说明

And here is the code I've done.

ListView(
  padding: EdgeInsets.only(top: 0),
  children: <Widget>[
    Row(
      children: <Widget>[
        Container(color: Colors.red, height: 100, width: 100,),
        Container(color: Colors.blue, height: 50, width: 50,),
      ],
    ),
    Divider(),
    Row(
      children: <Widget>[
        Container(color: Colors.red, height: 300, width: 100,),
        Container(color: Colors.blue, height: 50, width: 50,),
      ],
    ),
  ],
)

So, how can I make the blue container automatically match the red container height?

Remove the height parameter of the child you want to expand and use IntrinsicHeight class like below.


ListView(
        padding: EdgeInsets.only(top: 0),
        children: <Widget>[
          IntrinsicHeight(
            child: Row(
              children: <Widget>[
                Container(color: Colors.red, height: 100, width: 100,),
                Container(color: Colors.blue,width: 100,),
              ],
            ),
          ),
          Divider(),
          IntrinsicHeight(
            child: Row(
              children: <Widget>[
                Container(color: Colors.red, height: 300, width: 100,),
                Container(color: Colors.blue, width: 50,),
              ],
            ),
          ),
        ],
      )

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM