用百分比将小部件放在堆栈中
问题内容:
假设我想将小部件放置在a内,Stack
但要使用堆栈位置的一定百分比而不是固定大小。怎么办呢?
我希望Positionned.fromRelativeRect
构造函数就是问题,使用0到1之间的浮点数。但是似乎没有。
Align
允许以百分比定位小部件。但是,heightFactor
并widthFactor
更改Align
大小而不是子大小。这不是我想要的。
问题答案:
您可以将Positioned.fill
和组合在一起LayoutBuilder
以达到这样的结果。
new Stack(
children: <Widget>[
new Positioned.fill(
child: new LayoutBuilder(
builder: (context, constraints) {
return new Padding(
padding: new EdgeInsets.only(top: constraints.biggest.height * .59, bottom: constraints.biggest.height * .31),
child: new Text("toto", textAlign: TextAlign.center,),
);
},
),
)
],
),