Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flutter 颤振:列中嵌套行,如何在不展开父列的情况下填充行_Flutter_Nested_Row - Fatal编程技术网

Flutter 颤振:列中嵌套行,如何在不展开父列的情况下填充行

Flutter 颤振:列中嵌套行,如何在不展开父列的情况下填充行,flutter,nested,row,Flutter,Nested,Row,这就是我所拥有的: 源代码: Container( width: 150, height: 150, color: Colors.grey, child: Center( child: Column( mainAxisSize: MainAxisSize.min, children: [ Container( height: 100,

这就是我所拥有的:

源代码:

Container(
      width: 150,
      height: 150,
      color: Colors.grey,
      child: Center(
        child: Column(
          mainAxisSize: MainAxisSize.min,
          children: [
            Container(
              height: 100,
              width: 100,
              color: Colors.green,
            ),
            Row(
              mainAxisSize: MainAxisSize.min,
              children: [
                Container(
                  child: Text('text'),
                  color: Colors.blue,
                ),
                Container(
                  child: Text('text'),
                  color: Colors.red,
                ),
              ],
            ),
          ],
        ),
      ),
    ),
如何使蓝色和红色的容器与绿色容器的宽度相匹配,而不使它们比绿色容器大

这就是我想要得到的,而不必为行中的容器使用固定with。此外,我在列中有多个元素,我不想使用固定大小

Container(
  width: 150,
  height: 150,
  color: Colors.grey,
  child: Center(
    child: Column(
      mainAxisSize: MainAxisSize.min,
      children: [
        Container(
          height: 100,
          width: 100,
          color: Colors.green,
        ),
        Container(
          width: 100,
          Row(
          mainAxisSize: MainAxisSize.min,
          children: [
          Expanded(
          child:
            Container(
              child: Text('text'),
              color: Colors.blue,
            ),
          ),
          Expanded(
          child:
            Container(
              child: Text('text'),
              color: Colors.red,
            ),
          ),
          ],
        ),
        ),
      ],
    ),
  ),
),

您只能使用扩展小部件包装行的子项。

如果大小固定,则可以向容器添加宽度,该容器将使用行小部件包装

我给出宽度50的原因是因为父容器的宽度已经为100,所以将剩余宽度指定给容器

Container(
        width: 150,
        height: 150,
        color: Colors.grey,
        child: Column(
          mainAxisSize: MainAxisSize.min,
          children: [
            Container(
              height: 100,
              width: 100,
              color: Colors.green,
            ),
            Row(
              mainAxisSize: MainAxisSize.min,
              children: [
                Container(
                  width: 50,
                  child: Text('text'),
                  color: Colors.blue,
                ),
                Container(
                  width: 50,
                  child: Text('text'),
                  color: Colors.red,
                ),
              ],
            ),
          ],
        ),
      ),

您可以使用灵活的小部件来提供固定的行宽度

Container(
          width: 150,
          height: 150,
          color: Colors.grey,
          child: Center(
            child: Column(
              mainAxisSize: MainAxisSize.min,
              children: [
                Container(
                  height: 100,
                  width: 100,
                  color: Colors.green,
                ),
                Container(
                  width: 100,
                  child: Row(
                    children: [
                      Flexible(
                        flex: 1,
                        fit: FlexFit.tight,
                        child: Container(
                          child: Text('text'),
                          color: Colors.blue,
                        ),
                      ),
                      Flexible(
                        flex: 1,
                        fit: FlexFit.tight,
                        child: Container(
                          child: Text('text'),
                          color: Colors.red,
                        ),
                      ),
                    ],
                  ),
                ),
              ],
            ),
          ),
        )

尝试此操作,您必须将exapended添加到行窗口小部件的children中

Container(
  padding: EdgeInsets.all(16),
  color: Colors.grey,
  child: Column(
    mainAxisSize: MainAxisSize.min,
    crossAxisAlignment: CrossAxisAlignment.stretch,
    children: [
      Container(
        color: Colors.green,
        child: Text('Hdddfhlsd', style: primaryTextStyle()),
      ),
      Row(
        mainAxisSize: MainAxisSize.max,
        children: [
          Expanded(
            child: Container(
              child: Text('text'),
              color: Colors.blue,
            ),
          ),
          Expanded(
            child: Container(
              child: Text('text'),
              color: Colors.red,
            ),
          ),
        ],
      )
    ],
  ),
)

这就是我想要的,但我不想为行的孩子使用固定的with。问题中的固定尺寸仅用于演示目的。嗨,我不希望蓝色和红色容器比绿色容器大。我编辑了我的问题,因为这是不清楚的。然后删除容器的宽度或用100宽度的容器包装行。或者删除容器的宽度并用固定大小的小部件包装整列。我希望这会对你有帮助:)谢谢你的回答,但我不想要固定的尺寸。在我的例子中,这是为了在底部包含一个图像和两个按钮。带的列取决于图像,底部的按钮应该填充可用空间,但不扩展容器。是的,但是我必须给父容器一个固定的大小。但是大小必须是灵活的。您好,在您的实现中,即使列中的第一个容器具有固定的宽度,列也会占用所有可用的垂直空间。这是因为我们在列中使用strech属性,以将容器限制为固定的高度,我们可以将其分配给主容器。
 **Replace your container by this **

Container(
    width: 150,
    height: 150,
    color: Colors.grey,
    child: Center(
      child: Column(
        mainAxisSize: MainAxisSize.min,
        children: [
          Container(
            width: 100,
             
            child: Column(
              children: [
                Container(
                  height: 100,
                  width: 100,
                  color: Colors.green,
                ),
                Row(
                  mainAxisSize: MainAxisSize.min,
                  children: [
                    Expanded(
                      child: Container(
                        child: Text('text'),
                        color: Colors.blue,
                      ),
                    ),
                    Expanded(
                      child: Container(
                        child: Text('text'),
                        color: Colors.red,
                      ),
                    ),
                  ],
                )
              ],
            ),
          ),
        ],
      ),
    ),
  )