简体   繁体   English

将小部件定位在堆栈中,在模拟器中或根据不同的屏幕尺寸更改 position。 Flutter

[英]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 发生了一些这样的变化。

图片来自一加6 Here is my code:-这是我的代码:-

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使用相对于屏幕大小的值,而不是为bottomleft参数硬编码值。 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.

相关问题 如何根据 flutter 中的不同屏幕尺寸对齐堆栈内的小部件 - How to align widget inside stack according to different screen sizes in flutter 不同屏幕尺寸的图像。 - Images for Different Screen sizes.? 平板电脑的设计应用程序以支持不同的屏幕尺寸。 - Designing application for tablets to support different screen sizes. Nexus 10模拟器上的不同屏幕尺寸和分辨率 - Different screen sizes and resolutions on Nexus 10 emulator 应用适合多种屏幕尺寸。 但我所知道的 - App fits multiple screen sizes. but one that I know of Android 仿真器屏幕尺寸 - Android emulator screen sizes 根据不同的屏幕尺寸调整自定义网格项目的高度和宽度 - Adjust the height and width of custom grid item according to different screen sizes 如何根据不同的屏幕尺寸在android中支持方向? - How to Support Orientation in android according to different screen sizes? 如何根据颤动中的屏幕更改文本大小和小部件大小? - How to change textsize and widget size according to screen in flutter? 在某些较小的屏幕尺寸下,Malayalam文本在TextView中不可见。 (英文文本没有问题) - Malayalam text goes out of view in TextView, in some smaller screen sizes. (No issues with English text)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM