![](/img/trans.png)
[英]How to align widget inside stack according to different screen sizes in flutter
[英]Positioned widget in a Stack changing position in emulator or according to different screen sizes. Flutter
我一直在嘗試像這樣在此圖像上對堆棧中的每個雲進行 position。
當我在我的一加 6 手機中檢查我的應用程序時,雲 position 發生了一些這樣的變化。
Cloud(
bottom: 355 ,
left: 135,
videoLink: 'https://giant.gfycat.com/WetDifficultHornbill.webm',
lineUpLink:
'https://firebasestorage.googleapis.com/v0/b/flash-chats-2f263.appspot.com/o/photo_2021-03-21_23-33-04.jpg?alt=media&token=e903e0c8-9bd5-4587-bb31-acf1c0ab4ba8',
),
class Cloud extends StatelessWidget {
Cloud({this.width,this.height,this.bottom,this.left,this.lineUpLink,this.right,this.top,this.videoLink});
final String videoLink;
final String lineUpLink;
final double bottom;
final double left;
final double right;
final double top;
final double height;
final double width;
@override
Widget build(BuildContext context) {
return Positioned(
bottom: bottom,
left: left,
width: width,
height: height,
top: top,
right: right,
child: IconButton(
icon: Image.asset('images/cloud30.png'),
onPressed: () {
final getLink = GetLink(
link: videoLink,
lineLink: lineUpLink,
);
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => VideoApp(link: getLink.link,lineupLink: getLink.lineLink,)),
);
},
),
);
}
}
那我現在該怎么辦?? 請幫忙
您可以嘗試使用MediaQuery使用相對於屏幕大小的值,而不是為bottom
和left
參數硬編碼值。 例如,
Cloud(
bottom: MediaQuery.of(context).size.height / 3,
left: MediaQuery.of(context).size.width / 2,
// other parameters
),
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.