Showing
2 changed files
with
55 additions
and
0 deletions
ScreenUtil.dart
0 → 100644
1 | +/* | ||
2 | + * Created by 李卓原 on 2018/9/20. | ||
3 | + * email: zhuoyuan93@gmail.com | ||
4 | + * 设计稿设备尺寸 1080 * 1920 px | ||
5 | + */ | ||
6 | + | ||
7 | +import 'dart:ui'; | ||
8 | + | ||
9 | +class ScreenUtil { | ||
10 | + static ScreenUtil instance; | ||
11 | + | ||
12 | + //设计稿的设备尺寸修改 (请修改成你的设计稿的尺寸) | ||
13 | + static const designWidth = 1080; | ||
14 | + static const designHeight = 1920; | ||
15 | + | ||
16 | + //设备的像素密度 | ||
17 | + static double pixelRatio = window.devicePixelRatio; | ||
18 | + | ||
19 | + //当前设备宽度 px | ||
20 | + static double screenWidth = window.physicalSize.width; | ||
21 | + | ||
22 | + //当前设备高度 px | ||
23 | + static double screenHeight = window.physicalSize.height; | ||
24 | + | ||
25 | + //状态栏高度 刘海屏会更高 | ||
26 | + static double StatusBarHeight = window.padding.top; | ||
27 | + | ||
28 | + //底部安全区距离 | ||
29 | + static double BottomBarHeight = window.padding.bottom; | ||
30 | + | ||
31 | + //相对于设计稿放大的倍数 | ||
32 | + var scaleWidth = screenWidth / designWidth / pixelRatio; | ||
33 | + var scaleHeight = screenHeight / designWidth / pixelRatio; | ||
34 | + | ||
35 | + static ScreenUtil getInstance() { | ||
36 | + if (instance == null) { | ||
37 | + instance = new ScreenUtil(); | ||
38 | + } | ||
39 | + return instance; | ||
40 | + } | ||
41 | + | ||
42 | + /** | ||
43 | + * 根据设计稿的设备宽度适配 | ||
44 | + * 高度也根据这个来做适配可以保证不变形 | ||
45 | + */ | ||
46 | + setWidth(int width) => width * scaleWidth; | ||
47 | + | ||
48 | + /** | ||
49 | + * 根据设计稿的设备高度适配 | ||
50 | + * 当发现设计稿中的一屏显示的与当前样式效果不符合时, | ||
51 | + * 或者形状有差异时,高度适配建议使用此方法 | ||
52 | + * 高度适配主要针对想根据设计稿的一屏展示一样的效果 | ||
53 | + */ | ||
54 | + setHeight(int height) => height * scaleHeight; | ||
55 | +} |
微信图片_20180921000611.png
0 → 100644

43.2 KB
-
Please register or login to post a comment