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

时间:2021-03-22 06:16:08

标签: android flutter widget stack frontend

我一直在尝试像这样将堆栈中的每个云定位在此图像上。

Image In Emulator

当我在一加 6 手机上查看我的应用程序时,云的位置发生了这样的变化。

Picture from One plus 6 这是我的代码:-

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

那我现在该怎么办??请帮忙

1 个答案:

答案 0 :(得分:2)

您可以尝试使用 forall scoping rules 相对于屏幕尺寸的值来代替 bottomleft 参数的硬编码值。例如,

Cloud(
  bottom: MediaQuery.of(context).size.height / 3,
  left: MediaQuery.of(context).size.width / 2,
  // other parameters
),
相关问题