flutter - Flutter 水平和垂直对齐小部件
问题描述
我正在做一个 Flutter 项目。我正在尝试创建一个如下图所示的小部件,但我无法做到。
所以我想要做的是创建一个Text
左上角的小部件(这个小部件的大小不是恒定的,取决于其中的文本)。我正在尝试将其他 2 个小部件与Text
:
Widget 1
水平对齐并与小部件居中,并Text
在其右侧,中间没有空格- 的
Widget 2
右边缘与小部件的右边缘垂直对齐Text
,并位于其下方(两个小部件之间没有空间)。
我尝试使用Column
andRow
小部件或使用 a来实现这一点,GridView
但我无法做到。
此自定义小部件的整体尺寸也必须缩小。
有人知道该怎么做吗?
谢谢你。
解决方案
这有效
Container(
width: double.infinity,
height: 300,
color: Colors.grey[200],
child: Column(
children: <Widget>[
Row(
children: [
Flexible(
flex: 2,
child: Container(
height: 200,
color: Colors.blue,
),
),
Flexible(
flex: 1,
child: Container(
height: 100,
color: Colors.green,
),
),
],
),
Row(
children: <Widget>[
Flexible(
flex: 2,
child: Align(
alignment: Alignment.centerRight,
child: Container(
width: 150,
height: 100,
color: Colors.orange,
),
),
),
Flexible(
flex: 1,
child: Container(),
),
],
),
],
),
),
推荐阅读
- jersey - 使用 glassfish 时,无法使用具有可注入参数的构造函数调用球衣的根资源
- c# - C# FluentMigrator.Runner 控制台应用程序设置每个会话的事务
- swift - 如何使用参数数组声明泛型方法
? - node.js - Cucumberjs - 在步骤定义中调用异步方法
- sql - 如何计算 PostgreSQL 中所有归属于 - 及其子级的实体?
- iis - 通过 Azure Pipelines 将 .NET Core Web 应用程序部署到 IIS 服务器时出现 500 错误
- git - 错误:git 在 SUSE 12.4 上找不到 https 的远程助手
- sql - Oracle中如何复用部分SQL代码
- javascript - 如何解决代理后面的 npm install 期间的连接问题?
- oauth - 使用 OAuth2 和 OpenID Connect 进行会话管理/撤销