flutter - Flutter:如何在 Column 中将容器大小设置为 wrap_content
问题描述
我想设置Container
大小动态我的意思是wrap_content
如何在颤动中做?
在下面的代码中,默认情况下采用全宽Container
,但我想将宽度设置Container
为Text()
Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisSize: MainAxisSize.max,
children: <Widget>[
Container(
margin: EdgeInsets.all(10),
alignment: Alignment.center,
color: Colors.orange[800],
child: Text("Hello How are you"),
),
Container(
margin: EdgeInsets.all(10),
alignment: Alignment.center,
color: Colors.yellow[800],
child: Text("Welcome"),
)
],
);
我明白了:
但我想要这个输出:
解决方案
最简单的解决方案是使用Align
.
Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Align(
child: Container(
margin: EdgeInsets.all(10),
color: Colors.orange[800],
child: Text("Hello How are you"),
),
),
Align(
child: Container(
margin: EdgeInsets.all(10),
color: Colors.yellow[800],
child: Text("Welcome"),
),
)
],
)
推荐阅读
- python - 如何摆脱在 python 中使用 with 语句创建的文件的输入/输出错误?
- java - 部署 Maven 工件时出现“401 Unauthorized”错误
- arcgis - 想要使用 ArcGIS Runtime API for Andriod 仅在现有图形叠加层中显示第一个结果
- python-3.x - 从 RSA 私钥中查找密码
- python - 从头开始实施扩张
- php - 如何在 PHP 中选择多个查询到 MySQL
- python-3.x - 如何保持恒定的行数
- html - 需要帮助解决杂散结束标记 (HTML) 错误
- node.js - TypeORM 原始 sql 查询参数不起作用?
- sql - 试图计算我的组织表中 2 个表中的 3 列出现的次数?我需要在一张表中加入事件