堆栈中的位置控件百分比
问题描述:
假设我想在一个Stack
内定位一个控件,但是堆栈位置的百分比而不是固定的大小。如何在扑动中做到这一点?堆栈中的位置控件百分比
我期望Positionned.fromRelativeRect
构造函数将是使用0和1之间的浮点数的东西。但似乎不是。
Align
允许以百分比定位小部件。但heightFactor
和widthFactor
更改Align
大小而不是子大小。这不是我想要的。
答
您可以合并Positionned.fill
和LayoutBuilder
以获得此类结果。
new Stack(
children: <Widget>[
new Positioned.fill(
child: new LayoutBuilder(
builder: (context, constaints) {
return new Padding(
padding: new EdgeInsets.only(top: constaints.biggest.height * .59, bottom: constaints.biggest.height * .31),
child: new Text("toto", textAlign: TextAlign.center,),
);
},
),
)
],
),