2017-10-08 67 views
0

假設我想在一個Stack內定位一個控件,但是堆棧位置的百分比而不是固定的大小。如何在撲動中做到這一點?堆棧中的位置控件百分比

我期望Positionned.fromRelativeRect構造函數將是使用0和1之間的浮點數的東西。但似乎不是。

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

回答

1

您可以合併Positionned.fillLayoutBuilder以獲得此類結果。

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,), 
      ); 
      }, 
     ), 
    ) 
    ], 
),