如何将小部件的中心Y与另一个的顶部边缘对齐

时间:2019-03-19 13:48:29

标签: flutter flutter-layout

我想达到如图所示的效果:

enter image description here

绿色小部件的大小固定。蓝色小部件放置在绿色小部件的上方(有一定间距)。蓝色小部件的大小可以在运行时更改。无论蓝色小部件的高度如何,我都不会始终将黄色小部件的顶部边缘与蓝色小部件的中心Y对齐。

如果要固定蓝色小部件的高度,则解决方案非常简单。但是,如果假设蓝色小部件的高度可以在运行时改变,那么如何实现此结果呢?

1 个答案:

答案 0 :(得分:0)

Here I think the widget you're looking for is Positioned it's allow you to define a position in a Stack Widget and you can define height inside. Here are the link to Video widget of the week and Official doc

I am thinking to an other trick: You can define a height variable for you blue box and you can set a marginTop to your yellow Widget at precisely height/2 then your yellow block would always let half your blue box out.

(It's working with this components but if it's included with more Widgets it may not do the trick)

Hope it helps !!