Skip to content

Commit e4b43ab

Browse files
author
李卓原
committed
v4.0.1
fix #176
1 parent 5144545 commit e4b43ab

File tree

8 files changed

+87
-92
lines changed

8 files changed

+87
-92
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@
66
* @Description: Update log
77
-->
88

9+
# 4.0.1
10+
- Modify the initialization unit to dp
11+
- delete screenWidthPx and screenHeightPx(No one use these method,I guess)
12+
13+
# 4.0.0
14+
- update to 4.0.0
15+
916
# 4.0.0-beta3
1017
- Optimize the way of initialization
1118

README.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ dependencies:
2323
flutter:
2424
sdk: flutter
2525
# add flutter_screenutil
26-
flutter_screenutil: ^4.0.0-beta3
26+
flutter_screenutil: ^4.0.1
2727
```
2828
### Add the following imports to your Dart code:
2929
```dart
@@ -34,7 +34,7 @@ import 'package:flutter_screenutil/flutter_screenutil.dart';
3434

3535
|Property|Type|Default Value|Description|
3636
|:---|:---|:---|:---|
37-
|designSize|Size|Size(1080, 1920)|The size of the device in the design draft, in px|
37+
|designSize|Size|Size(360, 690)|The size of the device in the design draft, in dp|
3838
|allowFontScaling|bool|false|Sets whether the font size is scaled according to the system's "font size" assist option|
3939

4040
### Initialize and set the fit size and font size to scale according to the system's "font size" accessibility option
@@ -59,22 +59,22 @@ class MyApp extends StatelessWidget {
5959
6060
//fill in the screen size of the device in the design
6161
62-
//default value : width : 1080px , height:1920px , allowFontScaling:false
62+
//default value : width : 360dp , height:690dp , allowFontScaling:false
6363
ScreenUtil.init(constraints);
6464
65-
//If the design is based on the size of the iPhone6 ​​(iPhone6 ​​750*1334)
66-
ScreenUtil.init(constraints, designSize: Size(750, 1334));
65+
//The size of the equipment in the design draft(360,690)
66+
ScreenUtil.init(constraints, designSize: Size(360, 690));
6767
6868
//If you want to set the font size is scaled according to the system's "font size" assist option
69-
ScreenUtil.init(constraints, designSize: Size(750, 1334), allowFontScaling: true);
69+
ScreenUtil.init(constraints, designSize: Size(360, 690), allowFontScaling: true);
7070
7171
```
7272

7373
### Use:
7474

7575
### API
7676

77-
#### Pass the px size of the design draft
77+
#### Pass the dp size of the design draft
7878

7979
```dart
8080
ScreenUtil().setWidth(540) (dart sdk>=2.6 : 540.w) //Adapted to screen width
@@ -87,19 +87,19 @@ ScreenUtil.init(constraints, designSize: Size(750, 1334), allowFontScaling: true
8787
ScreenUtil().screenWidth (dart sdk>=2.6 : 1.sw) //Device width
8888
ScreenUtil().screenHeight (dart sdk>=2.6 : 1.sh) //Device height
8989
ScreenUtil().bottomBarHeight //Bottom safe zone distance, suitable for buttons with full screen
90-
ScreenUtil().statusBarHeight //Status bar height , Notch will be higher Unit px
90+
ScreenUtil().statusBarHeight //Status bar height , Notch will be higher
9191
ScreenUtil().textScaleFactor //System font scaling factor
9292
93-
ScreenUtil().scaleWidth //Ratio of actual width dp to ui design
94-
ScreenUtil().scaleHeight //Ratio of actual height dp to ui design
93+
ScreenUtil().scaleWidth //The ratio of actual width to UI design
94+
ScreenUtil().scaleHeight //The ratio of actual height to UI design
9595
9696
0.2.sw //0.2 times the screen width
9797
0.5.sh //50% of screen height
9898
```
9999

100100
#### Adapt screen size:
101101

102-
Pass the px size of the design draft((The unit is the same as the unit at initialization)):
102+
Pass the dp size of the design draft((The unit is the same as the unit at initialization)):
103103

104104
Adapted to screen width: `ScreenUtil().setWidth(540)`,
105105

@@ -169,13 +169,13 @@ Column(
169169
crossAxisAlignment: CrossAxisAlignment.start,
170170
children: <Widget>[
171171
Text(
172-
'My font size is 24px on the design draft and will not change with the system.',
172+
'My font size is 24dp on the design draft and will not change with the system.',
173173
style: TextStyle(
174174
color: Colors.black,
175175
fontSize: ScreenUtil().setSp(24),
176176
)),
177177
Text(
178-
'My font size is 24px on the design draft and will change with the system.',
178+
'My font size is 24dp on the design draft and will change with the system.',
179179
style: TextStyle(
180180
color: Colors.black,
181181
fontSize: ScreenUtil()

README_CN.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# flutter_ScreenUtil
1+
# flutter_screenUtil
22

33
[![pub package](https://img.shields.io/pub/v/flutter_screenutil.svg)](https://pub.dartlang.org/packages/flutter_screenutil)
44

@@ -28,7 +28,7 @@ dependencies:
2828
flutter:
2929
sdk: flutter
3030
# 添加依赖
31-
flutter_screenutil: ^4.0.0-beta3
31+
flutter_screenutil: ^4.0.1
3232
```
3333
### 在每个使用的地方导入包:
3434
```dart
@@ -39,7 +39,7 @@ import 'package:flutter_screenutil/flutter_screenutil.dart';
3939

4040
|属性|类型|默认值|描述|
4141
|:---|:---|:---|:---|
42-
|designSize|Size|Size(1080, 1920)|设计稿中设备的尺寸(单位随意,但在使用过程中必须保持一致)|
42+
|designSize|Size|Size(360, 690)|设计稿中设备的尺寸(单位随意,但在使用过程中必须保持一致)|
4343
|allowFontScaling|bool|false|设置字体大小是否根据系统的“字体大小”辅助选项来进行缩放|
4444

4545
### 初始化并设置适配尺寸及字体大小是否根据系统的“字体大小”辅助选项来进行缩放
@@ -65,21 +65,21 @@ class MyApp extends StatelessWidget {
6565
}
6666
}
6767
68-
//默认 width : 1080px , height:1920px , allowFontScaling:false
68+
//默认 width : 360dp , height:690dp , allowFontScaling:false
6969
ScreenUtil.init(constraints);
7070
71-
//假如设计稿是按iPhone6的尺寸设计的(iPhone6 750*1334)
72-
ScreenUtil.init(constraints, designSize: Size(750, 1334));
71+
//传入设计稿的尺寸(例如(360,690))
72+
ScreenUtil.init(constraints, designSize: Size(360,690));
7373
7474
//设置字体大小根据系统的“字体大小”辅助选项来进行缩放,默认为false
75-
ScreenUtil.init(constraints, designSize: Size(750, 1334), allowFontScaling: true);
75+
ScreenUtil.init(constraints, designSize: Size(360,690), allowFontScaling: true);
7676
7777
```
7878

7979
### 使用
8080

8181
### API
82-
#### 传入设计稿的px尺寸 px px px !
82+
#### 传入设计稿的dp尺寸
8383
```dart
8484
ScreenUtil().setWidth(540) (sdk>=2.6 : 540.w) //根据屏幕宽度适配尺寸
8585
ScreenUtil().setHeight(200) (sdk>=2.6 : 200.h) //根据屏幕高度适配尺寸(一般根据宽度适配即可)
@@ -94,8 +94,8 @@ ScreenUtil.init(constraints, designSize: Size(750, 1334), allowFontScaling: true
9494
ScreenUtil.statusBarHeight //状态栏高度 刘海屏会更高
9595
ScreenUtil.textScaleFactor //系统字体缩放比例
9696
97-
ScreenUtil().scaleWidth // 实际宽度的dp与设计稿宽度的比例
98-
ScreenUtil().scaleHeight // 实际高度的dp与设计稿高度度的比例
97+
ScreenUtil().scaleWidth // 实际宽度设计稿宽度的比例
98+
ScreenUtil().scaleHeight // 实际高度与设计稿高度度的比例
9999
100100
0.2.sw //屏幕宽度的0.2倍
101101
0.5.sh //屏幕高度的50%
@@ -169,12 +169,12 @@ ScreenUtil().setSp(24, allowFontScalingSelf: true)
169169
Column(
170170
crossAxisAlignment: CrossAxisAlignment.start,
171171
children: <Widget>[
172-
Text('我的文字大小在设计稿上是24px,不会随着系统的文字缩放比例变化',
172+
Text('我的文字大小在设计稿上是24dp,不会随着系统的文字缩放比例变化',
173173
style: TextStyle(
174174
color: Colors.black,
175175
fontSize: ScreenUtil().setSp(24),
176176
)),
177-
Text('我的文字大小在设计稿上是24px,会随着系统的文字缩放比例变化',
177+
Text('我的文字大小在设计稿上是24dp,会随着系统的文字缩放比例变化',
178178
style: TextStyle(
179179
color: Colors.black,
180180
fontSize: ScreenUtil()

README_PT.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ dependencies:
2424
flutter:
2525
sdk: flutter
2626
# add flutter_screenutil
27-
flutter_screenutil: ^4.0.0-beta3
27+
flutter_screenutil: ^4.0.1
2828
```
2929
3030
### Adicione o seguinte import em seu código Dart:
@@ -36,8 +36,8 @@ import 'package:flutter_screenutil/flutter_screenutil.dart';
3636

3737
|Propriedade|Tipo|Valor Padrão|Descrição|
3838
|:---|:---|:---|:---|
39-
|width|double|1080px|A largura do dispositivo no protótipo de design, em px|
40-
|height|double|1920px|A altura do dispositivo no protótipo de design, em px|
39+
|width|double|360dp|A largura do dispositivo no protótipo de design, em dp|
40+
|height|double|690dp|A altura do dispositivo no protótipo de design, em dp|
4141
|allowFontScaling|bool|false|Defina caso o tamanho da fonte seja dimensionado de acordo com a opção "tamanho de fonte" na acessibilidade do sistema|
4242

4343
### Inicialize e defina o tamanho de ajuste e tamanho da fonte para dimensionar de acordo com a opção "tamanho de fonte" na acessibilidade do sistema
@@ -61,14 +61,14 @@ class MyApp extends StatelessWidget {
6161
}
6262
}
6363
64-
//Valor padrão: width : 1080px , height:1920px , allowFontScaling:false
64+
//Valor padrão: width : 360dp , height:690dp , allowFontScaling:false
6565
ScreenUtil.init(constraints);
6666
67-
//Se o design é baseado no iPhone6 ​​(iPhone6 ​​750*1334)
68-
ScreenUtil.init(constraints, designSize: Size(750, 1334));
67+
//The size of the equipment in the design draft(360,690)
68+
ScreenUtil.init(constraints, designSize: Size(360,690));
6969
7070
//Se você quer definir que o tamanho da fonte seja ajustado de acordo com a opção "tamanho da fonte" na acessibilidade do sistema
71-
ScreenUtil.init(constraints, designSize: Size(750, 1334), allowFontScaling: true);
71+
ScreenUtil.init(constraints, designSize: Size(360,690), allowFontScaling: true);
7272
7373
```
7474

@@ -87,11 +87,11 @@ ScreenUtil.init(constraints, designSize: Size(750, 1334), allowFontScaling: true
8787
ScreenUtil.screenWidth (sdk>=2.6 : 1.sw) //Device width
8888
ScreenUtil.screenHeight (sdk>=2.6 : 1.sh) //Device height
8989
ScreenUtil.bottomBarHeight //Bottom safe zone distance, suitable for buttons with full screen
90-
ScreenUtil.statusBarHeight //Status bar height , Notch will be higher Unit px
90+
ScreenUtil.statusBarHeight //Status bar height , Notch will be higher
9191
ScreenUtil.textScaleFactor //System font scaling factor
9292
93-
ScreenUtil().scaleWidth //Ratio of actual width dp to design draft px
94-
ScreenUtil().scaleHeight //Ratio of actual height dp to design draft px
93+
ScreenUtil().scaleWidth //The ratio of actual width to UI design
94+
ScreenUtil().scaleHeight //The ratio of actual height to UI design
9595
9696
0.2.sw //0,2 vezes a largura da tela
9797
0.5.sh //50% altura da tela

example/lib/main.dart

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class MyApp extends StatelessWidget {
88
Widget build(BuildContext context) {
99
//Set the fit size (fill in the screen size of the device in the design) If the design is based on the size of the iPhone6 ​​(iPhone6 ​​750*1334)
1010
return ScreenUtilInit(
11-
designSize: Size(750, 1334),
11+
designSize: Size(360, 690),
1212
allowFontScaling: false,
1313
child: MaterialApp(
1414
debugShowCheckedModeBanner: false,
@@ -54,65 +54,63 @@ class _HomePageState extends State<HomePage> {
5454
height: 200.h,
5555
color: Colors.red,
5656
child: Text(
57-
'My width:${0.5.sw}dp \n'
58-
'My height:${200.h}dp',
57+
'My actual width: ${0.5.sw}dp \n\n'
58+
'My actual height: ${200.h}dp',
5959
style: TextStyle(
6060
color: Colors.white,
61-
fontSize: 24.sp,
61+
fontSize: 12.sp,
6262
),
6363
),
6464
),
6565
// Without using Extensions
6666
Container(
6767
padding: EdgeInsets.all(ScreenUtil().setWidth(10)),
68-
width: ScreenUtil().screenWidth * 0.5,
68+
width: 180.w,
6969
height: ScreenUtil().setHeight(200),
7070
color: Colors.blue,
7171
child: Text(
72-
'My width:${ScreenUtil().screenWidth * 0.5}dp \n'
73-
'My height:${ScreenUtil().setHeight(200)}dp',
72+
'My design draft width: 180dp\n\n'
73+
'My design draft height: 200dp',
7474
style: TextStyle(
7575
color: Colors.white,
76-
fontSize: ScreenUtil().setSp(24),
76+
fontSize: ScreenUtil().setSp(12),
7777
),
7878
),
7979
),
8080
],
8181
),
82-
Text('Device width:${ScreenUtil().screenWidthPx}px'),
83-
Text('Device height:${ScreenUtil().screenHeightPx}px'),
8482
Text('Device width:${ScreenUtil().screenWidth}dp'),
8583
Text('Device height:${ScreenUtil().screenHeight}dp'),
8684
Text('Device pixel density:${ScreenUtil().pixelRatio}'),
8785
Text('Bottom safe zone distance:${ScreenUtil().bottomBarHeight}dp'),
8886
Text('Status bar height:${ScreenUtil().statusBarHeight}dp'),
8987
Text(
90-
'Ratio of actual width dp to design draft px:${ScreenUtil().scaleWidth}',
88+
'The ratio of actual width to UI design:${ScreenUtil().scaleWidth}',
9189
textAlign: TextAlign.center,
9290
),
9391
Text(
94-
'Ratio of actual height dp to design draft px:${ScreenUtil().scaleHeight}',
92+
'The ratio of actual height to UI design:${ScreenUtil().scaleHeight}',
9593
textAlign: TextAlign.center,
9694
),
9795
SizedBox(
98-
height: 5.h,
96+
height: 50.h,
9997
),
10098
Text('System font scaling factor:${ScreenUtil().textScaleFactor}'),
10199
Column(
102100
crossAxisAlignment: CrossAxisAlignment.start,
103101
children: <Widget>[
104102
Text(
105-
'My font size is 24px on the design draft and will not change with the system.',
103+
'My font size is 16sp on the design draft and will not change with the system.',
106104
style: TextStyle(
107105
color: Colors.black,
108-
fontSize: 24.sp,
106+
fontSize: 16.sp,
109107
),
110108
),
111109
Text(
112-
'My font size is 24px on the design draft and will change with the system.',
110+
'My font size is 16sp on the design draft and will change with the system.',
113111
style: TextStyle(
114112
color: Colors.black,
115-
fontSize: 24.ssp,
113+
fontSize: 16.ssp,
116114
),
117115
),
118116
],
@@ -129,8 +127,8 @@ class _HomePageState extends State<HomePage> {
129127
print('Device pixel density:${ScreenUtil().pixelRatio}');
130128
print('Bottom safe zone distance dp:${ScreenUtil().bottomBarHeight}dp');
131129
print('Status bar height dp:${ScreenUtil().statusBarHeight}dp');
132-
print('Ratio of actual width dp to UI Design:${ScreenUtil().scaleWidth}');
133-
print('Ratio of actual height dp to UI Design:${ScreenUtil().scaleHeight}');
130+
print('The ratio of actual width to UI design:${ScreenUtil().scaleWidth}');
131+
print('The ratio of actual height to UI design:${ScreenUtil().scaleHeight}');
134132
print('System font scaling:${ScreenUtil().textScaleFactor}');
135133
print('0.5 times the screen width:${0.5.sw}dp');
136134
print('0.5 times the screen height:${0.5.sh}dp');

0 commit comments

Comments
 (0)