如何在Flutter行内的列中使用Container填充空间?

ken

以下是我在Flutter中的代码。

class MyListPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.white,
      body: _ListView(),
    );
  }
}

class _ListView extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return ListView.builder(
        itemCount: 1,
        itemBuilder: (_, index) {
          return MyTile();
        }
    );
  }
}

class MyTile extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Container(
      height: 100,
      color: Colors.red,
      child: Row(
        children: [
          Column(
            children: [
              Text("AAA"),
              SizedBox(height: 10,),
              Text("BBB"),
              SizedBox(height: 10,),
              Text("CCC\nDDD"),
              SizedBox(height: 10,),
            ],
          ),
          Column(
            children: [
              Text("aaaa"),
              Expanded(
                child: Container(
                  color: Colors.blue,
                  width: 20,
                ),
              ),
            ],
          ),
        ]
      ),
    );
  }
}

输出为以下图像。

在此处输入图片说明

但这不是我想要画的。我希望蓝色容器小部件可以像下面的图像一样填充多余的空间。黄色文字是我的补充评论。

在此处输入图片说明

然后,我更改width: 20,width: double.infinity,但是导致构建错误。

======== Exception caught by rendering library =====================================================
The following assertion was thrown during performLayout():
BoxConstraints forces an infinite width.

我该如何解决这个问题?

=======

[其他评论]

我已经删除了width如下属性。

          Column(
            children: [
              Text("aaaa"),
              Expanded(
                child: Container(
                  color: Colors.blue,
                ),
              ),
            ],
          ),

然后,蓝色容器被完全隐藏。宽度大概为零...

在此处输入图片说明

蒂埃里

您应该扩展第二列并使用拉伸横轴对齐方式:

class MyTile extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Container(
      height: 100,
      color: Colors.red,
      child: Row(children: [
        Column(
          children: [
            Text("AAA"),
            SizedBox(
              height: 10,
            ),
            Text("BBB"),
            SizedBox(
              height: 10,
            ),
            Text("CCC\nDDD"),
            SizedBox(
              height: 10,
            ),
          ],
        ),
        Expanded(
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.stretch,
            children: [
              Text("aaaa"),
              Expanded(
                child: Container(
                  color: Colors.blue,
                  width: 20,
                ),
              ),
            ],
          ),
        ),
      ]),
    );
  }
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何在Android中使用TextView填充视图的剩余空间?

如何在 tkinter 中使用网格系统填充空白空间?

如何在 CSS 中使用 div 标签填充空间?(包括图像)

如何在Java中使用Selenium执行内部滚动

如何在flutter中使用Canvas裁剪png图像并删除其未使用的空间?

如何在datagridview中使用列表填充列表中的一列而其他填充?

如何在Grails中使用休眠空间?

如何在简单的语法中使用空间

如何在Flutter中使用媒体查询添加填充?

如何通过使用填充或在mongodb中使用聚合进行内部查询来使用填充功能

如何在Excel中使用受保护的列和VBA自动填充列删除行

如何在 Angular 中使用 ng-container 和 ngFor 呈现的项目之间添加常规(中断)空间以允许自动换行

在C#中使用select时如何在列中放置空间

如何在行内块按钮之间创建空间?

如何在Ubuntu中使用未使用的空间

如何在Flutter中使用RevenueCat PurchaserInfoUpdateListener

如何在Flutter中使用CircularProgressIndicator

如何在Flutter插件中使用cocoapods?

如何在Flutter中使用SharedPreferences?

如何在Flutter的Webview中使用GeoLocation

Flutter,如何在Dismissible中使用confirmDismiss?

Flutter:如何在SliverAppBar中使用RefreshIndicator

如何在Flutter中使用Google API?

如何在Flutter SDK中使用OpenCV?

如何在Flutter中使用RGB颜色?

如何在Flutter中使用下限?

如何在Flutter的列表中使用Future?

如何在Flutter中使用DivorTiles()?

如何在Flutter中使用集合for循环?