颤振如何计算屏幕宽度 [英] How flutter calculates screen width

查看:60
本文介绍了颤振如何计算屏幕宽度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的抖动设置,可以在分辨率为2960 * 1440的设备上获取屏幕的宽度.

I have a simple flutter setup to get the width of the screen on device with resolution 2960*1440.

但是,当我以2960 * 1440的分辨率运行应用程序时,flutter返回的屏幕宽度为411.颤动如何计算设备的宽度?

However, flutter returns a screen width of 411 when I run the application on resolution 2960*1440. How does flutter calculate width of a device?

class page extends StatelessWidget {

  @override
  Widget build(BuildContext context) {
    final width = MediaQuery.of(context).size.width.toString();

    return Container(
      child: Text("Height : $height and Width : $width"),

    );
  }
}

推荐答案

颤动取决于MediaQuery方法来计算屏幕尺寸:

flutter depends on the MediaQuery method to calculate screen size :

  MediaQuery.of(context).size.width ;

根据文档,它返回屏幕上的逻辑像素",每个像素代表一个物理像素,其像素因设备而异.如果您想要实际的像素数,则可以使用:

as per the documentation it returns the number of the "logical pixels" of your screen which each one of them represent several physical pixels by a factor that differs from a device to another, and if you want the actual number of pixels you can use :

  MediaQuery.of(context).size.width * MediaQuery.of(context).devicePixelRatio ;

以及屏幕高度的实际像素:

and for the actual pixels of your screen height:

  MediaQuery.of(context).size.height * MediaQuery.of(context).devicePixelRatio ;

这篇关于颤振如何计算屏幕宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆