颤振如何计算屏幕宽度
问题内容:
我有一个简单的抖动设置,可以在分辨率为2960 * 1440的设备上获取屏幕的宽度。
但是,当我以2960 * 1440的分辨率运行应用程序时,flutter返回的屏幕宽度为411。颤振如何计算设备的宽度?
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
计算屏幕尺寸的方法:
MediaQuery.of(context).size.width ;
根据文档,
它返回屏幕的“逻辑像素”数,其中每个逻辑像素代表一个物理像素,其像素因设备而异,如果要获得实际的像素数,则可以使用:
MediaQuery.of(context).size.width * MediaQuery.of(context).devicePixelRatio ;
以及屏幕高度的实际像素:
MediaQuery.of(context).size.height * MediaQuery.of(context).devicePixelRatio ;