Skip to content

Commit 79c1ea9

Browse files
committed
2.2.0
fix #129
1 parent bd7355c commit 79c1ea9

File tree

8 files changed

+41
-10
lines changed

8 files changed

+41
-10
lines changed

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@
55
* @LastEditTime: 2020年6月20日 11:20:02
66
* @Description: Update log
77
-->
8-
8+
9+
# 2.2.0
10+
- add 'wp','hp'. Get the height/width of the screen proportionally
11+
- For example: 0.5.wp : Half the width of the screen.
12+
913
# 2.1.0
1014
- add 'nsp' , you can use 'fontSize: 24.nsp' instead of 'fontSize: ScreenUtil().setSp(24, allowFontScalingSelf: false)'
1115

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,17 @@ ScreenUtil.init(width: 750, height: 1334, allowFontScaling: true); /
7474
ScreenUtil().setSp(24, allowFontScalingSelf: false) (sdk>=2.6 : 24.nsp) //Adapter font(fonts will not scale to respect Text Size accessibility settings)
7575
7676
ScreenUtil.pixelRatio //Device pixel density
77-
ScreenUtil.screenWidth //Device width
78-
ScreenUtil.screenHeight //Device height
77+
ScreenUtil.screenWidth (sdk>=2.6 : 1.wp) //Device width
78+
ScreenUtil.screenHeight (sdk>=2.6 : 1.hp) //Device height
7979
ScreenUtil.bottomBarHeight //Bottom safe zone distance, suitable for buttons with full screen
8080
ScreenUtil.statusBarHeight //Status bar height , Notch will be higher Unit px
8181
ScreenUtil.textScaleFactor //System font scaling factor
8282
8383
ScreenUtil().scaleWidth //Ratio of actual width dp to design draft px
8484
ScreenUtil().scaleHeight //Ratio of actual height dp to design draft px
85+
86+
0.2.wp //0.2 times the screen width
87+
0.5.hp //50% of screen width
8588
```
8689

8790
#### Adapt screen size:

README_CN.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,17 @@ ScreenUtil.init(width: 750, height: 1334, allowFontScaling: true); /
7878
ScreenUtil().setSp(24, allowFontScalingSelf: false) (sdk>=2.6 : 24.nsp) //适配字体(不会根据系统的“字体大小”辅助选项来进行缩放)
7979
8080
ScreenUtil.pixelRatio //设备的像素密度
81-
ScreenUtil.screenWidth //设备宽度
82-
ScreenUtil.screenHeight //设备高度
81+
ScreenUtil.screenWidth (sdk>=2.6 : 1.wp) //设备宽度
82+
ScreenUtil.screenHeight (sdk>=2.6 : 1.hp) //设备高度
8383
ScreenUtil.bottomBarHeight //底部安全区距离,适用于全面屏下面有按键的
8484
ScreenUtil.statusBarHeight //状态栏高度 刘海屏会更高 单位px
8585
ScreenUtil.textScaleFactor //系统字体缩放比例
8686
8787
ScreenUtil().scaleWidth // 实际宽度的dp与设计稿px的比例
8888
ScreenUtil().scaleHeight // 实际高度的dp与设计稿px的比例
89+
90+
0.2.wp //屏幕宽度的0.2倍
91+
0.5.hp //屏幕宽度的50%
8992
```
9093

9194

README_PT.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,17 @@ ScreenUtil.init(width: 750, height: 1334, allowFontScaling: true); /
7474
ScreenUtil().setSp(24, allowFontScalingSelf: false) (sdk>=2.6 : 24.nsp) //Adapter font(fonts will not scale to respect Text Size accessibility settings)
7575
7676
ScreenUtil.pixelRatio //Device pixel density
77-
ScreenUtil.screenWidth //Device width
78-
ScreenUtil.screenHeight //Device height
77+
ScreenUtil.screenWidth (sdk>=2.6 : 1.wp) //Device width
78+
ScreenUtil.screenHeight (sdk>=2.6 : 1.hp) //Device height
7979
ScreenUtil.bottomBarHeight //Bottom safe zone distance, suitable for buttons with full screen
8080
ScreenUtil.statusBarHeight //Status bar height , Notch will be higher Unit px
8181
ScreenUtil.textScaleFactor //System font scaling factor
8282
8383
ScreenUtil().scaleWidth //Ratio of actual width dp to design draft px
8484
ScreenUtil().scaleHeight //Ratio of actual height dp to design draft px
85+
86+
0.2.wp //0,2 vezes a largura da tela
87+
0.5.hp //50% da largura da tela
8588
```
8689

8790
#### Adaptar o tamanho da tela:

example/lib/main.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class _ExampleWidgetState extends State<ExampleWidget> {
7373
height: ScreenUtil().setHeight(200),
7474
color: Colors.blue,
7575
child: Text(
76-
'My width:${ScreenUtil().setWidth(375)}dp \n'
76+
'My width:${0.5.wp}dp \n'
7777
'My height:${ScreenUtil().setHeight(200)}dp',
7878
style: TextStyle(
7979
color: Colors.white,
@@ -148,5 +148,7 @@ class _ExampleWidgetState extends State<ExampleWidget> {
148148
print(
149149
'The ratio of height width to the size of the design:${ScreenUtil().scaleHeight * ScreenUtil.pixelRatio}');
150150
print('System font scaling:${ScreenUtil.textScaleFactor}');
151+
print('0.5 times the screen width:${0.5.wp}');
152+
print('0.5 times the screen height:${0.5.hp}');
151153
}
152154
}

example/lib/main_zh.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ class _ExampleWidgetState extends State<ExampleWidget> {
6666
height: ScreenUtil().setHeight(200),
6767
color: Colors.red,
6868
child: Text(
69-
'我的宽度:${ScreenUtil().setWidth(375)}dp \n'
69+
'我的宽度:${0.5.wp}dp \n'
7070
'我的高度:${ScreenUtil().setHeight(200)}dp',
7171
style: TextStyle(
7272
color: Colors.white, fontSize: ScreenUtil().setSp(24)),
@@ -149,5 +149,8 @@ class _ExampleWidgetState extends State<ExampleWidget> {
149149
'宽度和字体相对于设计稿放大的比例:${ScreenUtil().scaleWidth * ScreenUtil.pixelRatio}');
150150
print('高度相对于设计稿放大的比例:${ScreenUtil().scaleHeight * ScreenUtil.pixelRatio}');
151151
print('系统的字体缩放比例:${ScreenUtil.textScaleFactor}');
152+
153+
print('屏幕宽度的0.5:${0.5.wp}');
154+
print('屏幕高度的0.5:${0.5.hp}');
152155
}
153156
}

lib/size_extension.dart

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,26 @@
11
import 'package:flutter_screenutil/screenutil.dart';
22

33
extension SizeExtension on num {
4+
///[ScreenUtil.setWidth]
45
num get w => ScreenUtil().setWidth(this);
56

7+
///[ScreenUtil.setHeight]
68
num get h => ScreenUtil().setHeight(this);
79

10+
///[ScreenUtil.setSp]
811
num get sp => ScreenUtil().setSp(this);
912

13+
///[ScreenUtil.setSp]
1014
num get ssp => ScreenUtil().setSp(this, allowFontScalingSelf: true);
1115

16+
///[ScreenUtil.setSp]
1217
num get nsp => ScreenUtil().setSp(this, allowFontScalingSelf: false);
18+
19+
///屏幕宽度的倍数
20+
///Multiple of screen width
21+
num get wp => ScreenUtil.screenWidth * this;
22+
23+
///屏幕高度的倍数
24+
///Multiple of screen height
25+
num get hp => ScreenUtil.screenHeight * this;
1326
}

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: flutter_screenutil
22
description: A flutter plugin for adapting screen and font size.Guaranteed to look good on different models
3-
version: 2.1.0
3+
version: 2.2.0
44
homepage: https://github.com/OpenFlutter/flutter_screenutil
55

66
environment:

0 commit comments

Comments
 (0)