我有一个简单的颤振设置,以获得分辨率为2960 * 1440的设备屏幕宽度。
但是,当我在2960 * 1440分辨率下运行应用程序时,颤振返回的屏幕宽度为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 ;
根据documentation,它返回屏幕的“逻辑像素”的数量,它们中的每一个代表几个物理像素,这个因素与设备不同,如果你想要实际的像素数,你可以使用:
MediaQuery.of(context).size.width * MediaQuery.of(context).devicePixelRatio ;
以及屏幕高度的实际像素:
MediaQuery.of(context).size.height * MediaQuery.of(context).devicePixelRatio ;