[英]Positioned widget in a Stack changing position in emulator or according to different screen sizes. Flutter
I have been trying to position each cloud in the stack over this image like this.我一直在尝试像这样在此图像上对堆栈中的每个云进行 position。
And when I checked my app in my One Plus 6 phone the clouds position were changed a little bit like this.当我在我的一加 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,)),
);
},
),
);
}
}
So what should I do now??那我现在该怎么办?? pls help
请帮忙
Instead of hard-coded values for bottom
and left
parameters, you can try using values relative to the screen size using MediaQuery .您可以尝试使用MediaQuery使用相对于屏幕大小的值,而不是为
bottom
和left
参数硬编码值。 For example,例如,
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.