小编典典

用百分比将小部件放在堆栈中

flutter

假设我想将小部件放置在a内,Stack但要使用堆栈位置的一定百分比而不是固定大小。怎么办呢?

我希望Positionned.fromRelativeRect构造函数就是问题,使用0到1之间的浮点数。但是似乎没有。

Align允许以百分比定位小部件。但是,heightFactorwidthFactor更改Align大小而不是子大小。这不是我想要的。


阅读 318

收藏
2020-08-13

共1个答案

小编典典

您可以将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,),
            );
          },
        ),
      )
    ],
  ),
2020-08-13