Positioned widget in a Stack changing position in emulator or according to different screen sizes. Flutter

Viewed 197

I have been trying to position each cloud in the stack over this image like this.

Image In Emulator

And when I checked my app in my One Plus 6 phone the clouds position were changed a little bit like this.

Picture from One plus 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

1 Answers

Instead of hard-coded values for bottom and left parameters, you can try using values relative to the screen size using MediaQuery. For example,

Cloud(
  bottom: MediaQuery.of(context).size.height / 3,
  left: MediaQuery.of(context).size.width / 2,
  // other parameters
),
Related