前言
想要記錄一下Stack布局中唧领,定位的兩種方式
代碼
//……省略無關代碼……
child: new Column(
children: <Widget>[
new SizedBox(height: 20.0),
new Stack(
alignment: const FractionalOffset(0.9, 0.1),//方法一辨图,括號里的值范圍是0~1
children: <Widget>[
new Image(
image: new AssetImage("assets/images/illustration_11.jpg"),
width: 300.0,
height: 200.0,
fit: BoxFit.cover,
),
new Opacity(
opacity: 0.8,
child: new Image(
image: new AssetImage("assets/images/illustration_12.jpg"),
width: 200.0,
height: 150.0,
fit: BoxFit.cover,
),
),
new GestureDetector(
onTap: () {
Fluttertoast.showToast(msg: "分享一下咯");
},
child: new Icon(Icons.share, color: Colors.white),
),
],
),
new SizedBox(height: 20.0),
new Stack(
children: <Widget>[
new Image(
image: new AssetImage("assets/images/illustration_11.jpg"),
width: 300.0,
height: 200.0,
fit: BoxFit.cover,
),
new Positioned(//方法二
right: 15.0,
top: 15.0,
child: new Icon(
Icons.share,
color: Colors.white,
),
),
],
)
],
),
//……省略無關代碼……
方法一
使用alignment配合FractionalOffset
:對于FractionalOffset的參數(shù)员凝,我是這么理解的:相當于比例拿穴,第一個代表橫向的權重严卖,第二個代表豎向的權重宴抚,橫0.9代表在橫向十分之九的位置,豎0.1代表在豎向十分之一的位置
方法二
使用定位組件Positioned
践图,其中的top掺冠、right、buttom码党、left德崭,直接代表斥黑,距離該方向的距離
效果
image
另外定位還可以使用Align