【发布时间】:2020-03-17 03:50:43
【问题描述】:
项目
嗨, 我试图在 Flutter 的 Stack 中对齐一些小部件。我的最终结果是这样的:
我知道这可以通过 Row 轻松实现,但我想为两个孩子的位置设置动画,所以我不得不使用堆栈。
我的问题很简单:
示例代码
return Container(
child: Stack(
children: <Widget>[
Align(
alignment: Alignment.centerLeft,
child: _buildSign(),
),
Align(
alignment: Alignment.centerRight,
child: _buildSign(),
),
],
),
);
这不会像我预期的那样呈现。无论我在 alignment 字段中输入什么内容:Alignment.centerRight 和 Alignment.centerLeft 都会始终将孩子放在左侧中间。
只有给包装容器一个固定的宽度才能解决问题。现在我明白为什么会发生这种情况了,但是如果我想让容器和他的孩子一样大怎么办?标签是动态文本,所以他的宽度对我来说是不可预测的
有什么想法吗?
谢谢
【问题讨论】:
-
"I know that this can be easily achieved with a Row but I want to animate the position ot the two children so I'm forced to use stack."所以请改用Flow 小部件(点击演示影片查看其工作原理)