Skip to content

Commit 11a2638

Browse files
author
李卓原
committed
Merge branch 'v4'
null safety.1
2 parents 22687b9 + 959f188 commit 11a2638

File tree

9 files changed

+158
-107
lines changed

9 files changed

+158
-107
lines changed

CHANGELOG.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,19 @@
1+
2+
# 5.0.0-nullsafety.1
3+
- merge 4.0.1 ,4.0.2 #183
4+
15
# 5.0.0-nullsafety.0
26
- Migrated flutter_screenutil to non-nullable
37

8+
# 4.0.2
9+
- add r(),adapt according to the smaller of width or height
10+
11+
# 4.0.1
12+
- Modify the initialization unit to dp
13+
- delete screenWidthPx and screenHeightPx(No one use these method,I guess)
14+
415
# 4.0.0
5-
- Upgrade to 4.0.0
16+
- update to 4.0.0
617

718
# 4.0.0-beta3
819
- Optimize the way of initialization

README.md

Lines changed: 26 additions & 17 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: ^5.0.0-nullsafety.0
26+
flutter_screenutil: ^5.0.0-nullsafety.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,26 +59,27 @@ 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
8181
ScreenUtil().setHeight(200) (dart sdk>=2.6 : 200.h) //Adapted to screen height , under normal circumstances, the height still uses x.w
82+
ScreenUtil().radius(200) (dart sdk>=2.6 : 200.r) //Adapt according to the smaller of width or height
8283
ScreenUtil().setSp(24) (dart sdk>=2.6 : 24.sp) //Adapter font
8384
ScreenUtil().setSp(24, allowFontScalingSelf: true) (dart sdk>=2.6 : 24.ssp) //Adapter font(fonts will scale to respect Text Size accessibility settings)
8485
ScreenUtil().setSp(24, allowFontScalingSelf: false) (dart sdk>=2.6 : 24.nsp) //Adapter font(fonts will not scale to respect Text Size accessibility settings)
@@ -87,19 +88,19 @@ ScreenUtil.init(constraints, designSize: Size(750, 1334), allowFontScaling: true
8788
ScreenUtil().screenWidth (dart sdk>=2.6 : 1.sw) //Device width
8889
ScreenUtil().screenHeight (dart sdk>=2.6 : 1.sh) //Device height
8990
ScreenUtil().bottomBarHeight //Bottom safe zone distance, suitable for buttons with full screen
90-
ScreenUtil().statusBarHeight //Status bar height , Notch will be higher Unit px
91+
ScreenUtil().statusBarHeight //Status bar height , Notch will be higher
9192
ScreenUtil().textScaleFactor //System font scaling factor
9293
93-
ScreenUtil().scaleWidth //Ratio of actual width dp to ui design
94-
ScreenUtil().scaleHeight //Ratio of actual height dp to ui design
94+
ScreenUtil().scaleWidth //The ratio of actual width to UI design
95+
ScreenUtil().scaleHeight //The ratio of actual height to UI design
9596
9697
0.2.sw //0.2 times the screen width
9798
0.5.sh //50% of screen height
9899
```
99100

100101
#### Adapt screen size:
101102

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

104105
Adapted to screen width: `ScreenUtil().setWidth(540)`,
105106

@@ -129,22 +130,30 @@ The height can also use setWidth to ensure that it is not deformed(when you want
129130

130131
setHeight method is mainly adapted in height, you want to control the height and actuality of a screen on the UIUsed when the same is displayed.
131132

133+
Generally speaking, 50.w!=50.h.
134+
132135
```dart
133136
//for example:
134137
135138
///If you want to display a square:
136-
///rectangle
139+
///The UI may show a rectangle:
137140
Container(
138-
width: ScreenUtil().setWidth(375),
139-
height: ScreenUtil().setWidth(200),
141+
width: 375.w,
142+
height: 375.h,
140143
),
141144
142145
////If you want to display a square:
143146
Container(
144-
width: ScreenUtil().setWidth(300),
147+
width: 300.w,
145148
height: 300.w,
146149
),
147150
151+
or
152+
153+
Container(
154+
width: 300.r,
155+
height: 300.r,
156+
),
148157
```
149158

150159

@@ -169,13 +178,13 @@ Column(
169178
crossAxisAlignment: CrossAxisAlignment.start,
170179
children: <Widget>[
171180
Text(
172-
'My font size is 24px on the design draft and will not change with the system.',
181+
'My font size is 24dp on the design draft and will not change with the system.',
173182
style: TextStyle(
174183
color: Colors.black,
175184
fontSize: ScreenUtil().setSp(24),
176185
)),
177186
Text(
178-
'My font size is 24px on the design draft and will change with the system.',
187+
'My font size is 24dp on the design draft and will change with the system.',
179188
style: TextStyle(
180189
color: Colors.black,
181190
fontSize: ScreenUtil()

README_CN.md

Lines changed: 23 additions & 20 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: ^5.0.0-nullsafety.0
31+
flutter_screenutil: ^5.0.0-nullsafety.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,25 +65,26 @@ 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
84-
ScreenUtil().setWidth(540) (sdk>=2.6 : 540.w) //根据屏幕宽度适配尺寸
85-
ScreenUtil().setHeight(200) (sdk>=2.6 : 200.h) //根据屏幕高度适配尺寸(一般根据宽度适配即可)
86-
ScreenUtil().setSp(24) (sdk>=2.6 : 24.sp) //适配字体
84+
ScreenUtil().setWidth(540) (sdk>=2.6 : 540.w) //根据屏幕宽度适配尺寸
85+
ScreenUtil().setHeight(200) (sdk>=2.6 : 200.h) //根据屏幕高度适配尺寸(一般根据宽度适配即可)
86+
ScreenUtil().radius(200) (sdk>=2.6 : 200.r) //根据宽度或高度中的较小者进行调整
87+
ScreenUtil().setSp(24) (sdk>=2.6 : 24.sp) //适配字体
8788
ScreenUtil().setSp(24, allowFontScalingSelf: true) (sdk>=2.6 : 24.ssp) //适配字体(根据系统的“字体大小”辅助选项来进行缩放)
8889
ScreenUtil().setSp(24, allowFontScalingSelf: false) (sdk>=2.6 : 24.nsp) //适配字体(不会根据系统的“字体大小”辅助选项来进行缩放)
8990
@@ -94,8 +95,8 @@ ScreenUtil.init(constraints, designSize: Size(750, 1334), allowFontScaling: true
9495
ScreenUtil.statusBarHeight //状态栏高度 刘海屏会更高
9596
ScreenUtil.textScaleFactor //系统字体缩放比例
9697
97-
ScreenUtil().scaleWidth // 实际宽度的dp与设计稿宽度的比例
98-
ScreenUtil().scaleHeight // 实际高度的dp与设计稿高度度的比例
98+
ScreenUtil().scaleWidth // 实际宽度设计稿宽度的比例
99+
ScreenUtil().scaleHeight // 实际高度与设计稿高度度的比例
99100
100101
0.2.sw //屏幕宽度的0.2倍
101102
0.5.sh //屏幕高度的50%
@@ -110,6 +111,8 @@ ScreenUtil.init(constraints, designSize: Size(750, 1334), allowFontScaling: true
110111

111112
根据屏幕高度适配 `height: ScreenUtil().setHeight(200)`, 一般来说,控件高度也根据宽度进行适配
112113

114+
一般来说,50.w!=50.h
115+
113116
**注意**
114117

115118
高度也根据setWidth来做适配可以保证不变形(当你想要一个正方形的时候)
@@ -119,16 +122,16 @@ setHeight方法主要是在高度上进行适配, 在你想控制UI上一屏的
119122
例如:
120123

121124
```dart
122-
//UI上是长方形:
125+
//UI可能显示长方形:
123126
Container(
124-
width: ScreenUtil().setWidth(375),
125-
height: ScreenUtil().setHeight(375),
127+
width: 375.w,
128+
height: 375.h,
126129
),
127130
128131
//如果你想显示一个正方形:
129132
Container(
130-
width: ScreenUtil().setWidth(300),
131-
height: ScreenUtil().setWidth(300),
133+
width: 300.r,
134+
height: 300.r,
132135
),
133136
```
134137

@@ -169,12 +172,12 @@ ScreenUtil().setSp(24, allowFontScalingSelf: true)
169172
Column(
170173
crossAxisAlignment: CrossAxisAlignment.start,
171174
children: <Widget>[
172-
Text('我的文字大小在设计稿上是24px,不会随着系统的文字缩放比例变化',
175+
Text('我的文字大小在设计稿上是24dp,不会随着系统的文字缩放比例变化',
173176
style: TextStyle(
174177
color: Colors.black,
175178
fontSize: ScreenUtil().setSp(24),
176179
)),
177-
Text('我的文字大小在设计稿上是24px,会随着系统的文字缩放比例变化',
180+
Text('我的文字大小在设计稿上是24dp,会随着系统的文字缩放比例变化',
178181
style: TextStyle(
179182
color: Colors.black,
180183
fontSize: ScreenUtil()

README_PT.md

Lines changed: 17 additions & 14 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: ^5.0.0-nullsafety.0
27+
flutter_screenutil: ^5.0.0-nullsafety.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

@@ -79,6 +79,7 @@ ScreenUtil.init(constraints, designSize: Size(750, 1334), allowFontScaling: true
7979
```dart
8080
ScreenUtil().setWidth(540) (sdk>=2.6 : 540.w) //Adapted to screen width
8181
ScreenUtil().setHeight(200) (sdk>=2.6 : 200.h) //Adapted to screen height
82+
ScreenUtil().radius(200) (dart sdk>=2.6 : 200.r) //Adapt according to the smaller of width or height
8283
ScreenUtil().setSp(24) (sdk>=2.6 : 24.sp) //Adapter font
8384
ScreenUtil().setSp(24, allowFontScalingSelf: true) (sdk>=2.6 : 24.ssp) //Adapter font(fonts will scale to respect Text Size accessibility settings)
8485
ScreenUtil().setSp(24, allowFontScalingSelf: false) (sdk>=2.6 : 24.nsp) //Adapter font(fonts will not scale to respect Text Size accessibility settings)
@@ -87,11 +88,11 @@ ScreenUtil.init(constraints, designSize: Size(750, 1334), allowFontScaling: true
8788
ScreenUtil.screenWidth (sdk>=2.6 : 1.sw) //Device width
8889
ScreenUtil.screenHeight (sdk>=2.6 : 1.sh) //Device height
8990
ScreenUtil.bottomBarHeight //Bottom safe zone distance, suitable for buttons with full screen
90-
ScreenUtil.statusBarHeight //Status bar height , Notch will be higher Unit px
91+
ScreenUtil.statusBarHeight //Status bar height , Notch will be higher
9192
ScreenUtil.textScaleFactor //System font scaling factor
9293
93-
ScreenUtil().scaleWidth //Ratio of actual width dp to design draft px
94-
ScreenUtil().scaleHeight //Ratio of actual height dp to design draft px
94+
ScreenUtil().scaleWidth //The ratio of actual width to UI design
95+
ScreenUtil().scaleHeight //The ratio of actual height to UI design
9596
9697
0.2.sw //0,2 vezes a largura da tela
9798
0.5.sh //50% altura da tela
@@ -129,19 +130,21 @@ Altura também é adaptada de acordo com o setWidth para garantir que não tenha
129130

130131
O método setHeight é a principal forma de adaptar a altura, se quiser controlar a altura e a realidade de uma tela na UiUsed quando a mesma for exibida.
131132

133+
Generally speaking, 50.w!=50.h.
134+
132135
```dart
133136
//Exemplo:
134137
//Retângulo
135138
Container(
136-
width: ScreenUtil().setWidth(375),
137-
height: ScreenUtil().setHeight(200),
139+
width: 375.w,
140+
height: 200.w,
138141
...
139142
),
140143
141144
////Se quiser exibir um quadrado:
142145
Container(
143-
width: ScreenUtil().setWidth(300),
144-
height: ScreenUtil().setWidth(300),
146+
width: 300.r,
147+
height: 300.r,
145148
),
146149
147150
```

0 commit comments

Comments
 (0)