展开容器以填充列中的剩余空间

art*_*iaz 4 dart flutter

我在颤振中构建特定布局时遇到问题。

我需要的是:可滚动屏幕,有两列,其中第一列具有一定的(但动态的)高度。第二列具有一定(但动态)高度的一部分,而其余的列我想填充剩余空间。

代码结构。

   Row(
      children: [
       Expanded(
         child: Column(children:[
            someDynamicHeightWidgetsHere()])),
       Expanded(child: Column(children: [
            someWidgetsHere(), 
            here fill remainind space to match the first column]))
       ]  
    )
Run Code Online (Sandbox Code Playgroud)

jit*_*555 7

使用IntrinsicHeight,该小部件仅扩展到其子级高度。例如,当高度不受限制并且您希望子级尝试无限扩展以将其自身调整为更合理的高度时,此类非常有用。

例子:

IntrinsicHeight(
        child: Row(
          children: [
            Expanded(
              child: Column(
                children: [
                  Container(
                    height: 800,
                    color: Colors.blue,
                  ),
                ],
              ),
            ),
            Expanded(
              child: Column(
                children: [
                  Container(
                    height: 400,
                    color: Colors.red,
                  ),
                  Expanded(
                    child: Container(
                      color: Colors.yellow,
                    ),
                  ),
                ],
              ),
            ),
          ],
        ),
Run Code Online (Sandbox Code Playgroud)

输出:

在此输入图像描述