6

flutter 的像素尺寸

 3 years ago
source link: https://blog.csdn.net/Ani/article/details/101263446
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
flutter 的像素尺寸_anakin.jin的专栏-CSDN博客

一般我们在android,ios中都有自己的尺寸,如:dp,pt

但是在flutter中写尺寸是没有单位的。如:

SizedBox(height: 736,width: 375,child: Container(color: Colors.lightBlueAccent) )

实际上它的尺寸当然是有的。 在不同设备中它与 devicePixelRatio 属性有关,通过此属性得到一个逻辑像素占用多少个实际像素,根据文档(https://api.flutter.dev/flutter/dart-ui/Window/devicePixelRatio.html)有几点需要注意:

  1. 很少需要修改这个值

  2. 这个值来自设备,可能会不准确

我用模拟器(下面列表中全部都是)来做测试,信息如下:

屏幕英寸分辨率实测宽度ppidevicePixelRatioandroid  5寸1080*19204124202.625iPhone8+ 5.5寸1080*19204144013iPhoneXr 6.1寸828 * 17924143262iPhone8 4.7寸750 * 13343753262iPhone7+ 5.5寸1080 * 19204144013iPhoneX 5.82436×11253754583iPhone 111792 x 828 像素分辨率414326 ppi2

实测宽度:在Flutter中,一个SizedBox的宽度刚好撑满屏幕宽度的数值

  除了 iPhone8+,iPhone7+ 之外,其它的 : 分辨率宽度 =  devicePixelRatio * 实测宽度

  怀疑 iPhone8+,7+ 的模拟器应该是Flutter存在BUG. 它的分辨率不是上面表格中的 1080 * 1920

        内部的数据:window.physicalSize.width = 1242 , MediaQuery.of(context).size.width = 414  

其它朋友写的文章 ,比较有帮助

https://www.cnblogs.com/ckAng/p/10077832.html


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK