Skip to content

Commit cff6d04

Browse files
committed
2.0.0
1 parent 77699ad commit cff6d04

File tree

10 files changed

+91
-78
lines changed

10 files changed

+91
-78
lines changed

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,14 @@
22
* @Author: [email protected]
33
* @Date: 2018-10-16 19:43:03
44
* @LastEditors: [email protected]
5-
* @LastEditTime: 2020年1月14日 12:11:02
5+
* @LastEditTime: 2020年6月20日 11:20:02
66
* @Description: Update log
77
-->
88

9+
#2.0.0
10+
- Use `MediaQueryData.fromWindow(window)` instead of `MediaQuery.of(context)`, no context parameter required
11+
- API changes, please note
12+
913
#1.1.0
1014
- support ExtensionMethod Dart-SDK-2.6.0
1115
- you can use 'width: 50.w' instead of 'width: ScreenUtil().setWidth(50)'

README.md

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,13 @@ github: https://github.com/OpenFlutter/flutter_screenutil
1818

1919
### Add dependency:
2020
Please check the latest version before installation.
21+
If there is any problem with the new version, please use the previous version
2122
```
2223
dependencies:
2324
flutter:
2425
sdk: flutter
2526
# add flutter_screenutil
26-
flutter_screenutil: ^1.0.2
27+
flutter_screenutil: ^2.0.0
2728
```
2829

2930
### Add the following imports to your Dart code:
@@ -48,13 +49,16 @@ Be sure to set the page in the MaterialApp's home(ie the entry file, just set it
4849
//fill in the screen size of the device in the design
4950
5051
//default value : width : 1080px , height:1920px , allowFontScaling:false
51-
ScreenUtil.init(context);
52+
ScreenUtil.init(context); //flutter_screenuitl < 1.2
53+
ScreenUtil.init(); //flutter_screenuitl >= 1.2
5254
5355
//If the design is based on the size of the iPhone6 ​​(iPhone6 ​​750*1334)
54-
ScreenUtil.init(context, width: 750, height: 1334);
56+
ScreenUtil.init(context, width: 750, height: 1334); //flutter_screenuitl < 1.2
57+
ScreenUtil.init(width: 750, height: 1334); //flutter_screenuitl >= 1.2
5558
5659
//If you want to set the font size is scaled according to the system's "font size" assist option
57-
ScreenUtil.init(context, width: 750, height: 1334, allowFontScaling: true);
60+
ScreenUtil.init(context, width: 750, height: 1334, allowFontScaling: true); //flutter_screenuitl < 1.2
61+
ScreenUtil.init(width: 750, height: 1334, allowFontScaling: true); //flutter_screenuitl >= 1.2
5862
5963
```
6064

@@ -189,7 +193,7 @@ class _MyHomePageState extends State<MyHomePage> {
189193
@override
190194
Widget build(BuildContext context) {
191195
//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)
192-
ScreenUtil.init(context, width: 750, height: 1334, allowFontScaling: false);
196+
ScreenUtil.init(width: 750, height: 1334, allowFontScaling: false);
193197
194198
return ExampleWidget(title: 'FlutterScreenUtil Demo');
195199
}
@@ -244,10 +248,10 @@ class _ExampleWidgetState extends State<ExampleWidget> {
244248
),
245249
],
246250
),
247-
Text('Device width:${ScreenUtil.screenWidth}px'),
248-
Text('Device height:${ScreenUtil.screenHeight}px'),
249-
Text('Device width:${ScreenUtil.screenWidthDp}dp'),
250-
Text('Device height:${ScreenUtil.screenHeightDp}dp'),
251+
Text('Device width:${ScreenUtil.screenWidth}dp'),
252+
Text('Device height:${ScreenUtil.screenHeight}dp'),
253+
Text('Device width:${ScreenUtil.screenWidthPx}px'),
254+
Text('Device height:${ScreenUtil.screenHeightPx}px'),
251255
Text('Device pixel density:${ScreenUtil.pixelRatio}'),
252256
Text('Bottom safe zone distance:${ScreenUtil.bottomBarHeight}dp'),
253257
Text('Status bar height:${ScreenUtil.statusBarHeight}dp'),
@@ -286,8 +290,7 @@ class _ExampleWidgetState extends State<ExampleWidget> {
286290
floatingActionButton: FloatingActionButton(
287291
child: Icon(Icons.title),
288292
onPressed: () {
289-
ScreenUtil.init(context,
290-
width: 1500, height: 1334, allowFontScaling: false);
293+
ScreenUtil.init(width: 1500, height: 1334, allowFontScaling: false);
291294
setState(() {});
292295
},
293296
),
@@ -302,7 +305,7 @@ class _ExampleWidgetState extends State<ExampleWidget> {
302305
print(
303306
'Bottom safe zone distance dp:${ScreenUtil.bottomBarHeight}'); //Bottom safe zone distance,suitable for buttons with full screen
304307
print(
305-
'Status bar height px:${ScreenUtil.statusBarHeight}dp'); //Status bar height , Notch will be higher Unit px
308+
'Status bar height dp:${ScreenUtil.statusBarHeight}dp'); //Status bar height , Notch will be higher Unit dp
306309
print(
307310
'Ratio of actual width dp to design draft px:${ScreenUtil().scaleWidth}');
308311
print(

README_CN.md

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,13 @@ csdn博客工具介绍:https://blog.csdn.net/u011272795/article/details/82795477
2323
### 安装依赖:
2424

2525
安装之前请查看最新版本
26+
新版本如有问题请使用上一版
2627
```
2728
dependencies:
2829
flutter:
2930
sdk: flutter
3031
# 添加依赖
31-
flutter_screenutil: ^1.0.2
32+
flutter_screenutil: ^2.0.0
3233
```
3334

3435
### 在每个使用的地方导入包:
@@ -52,13 +53,16 @@ import 'package:flutter_screenutil/flutter_screenutil.dart';
5253
//填入设计稿中设备的屏幕尺寸
5354
5455
//默认 width : 1080px , height:1920px , allowFontScaling:false
55-
ScreenUtil.init(context);
56+
ScreenUtil.init(context); //flutter_screenuitl < 1.2
57+
ScreenUtil.init(); //flutter_screenuitl >= 1.2
5658
5759
//假如设计稿是按iPhone6的尺寸设计的(iPhone6 750*1334)
58-
ScreenUtil.init(context, width: 750, height: 1334);
60+
ScreenUtil.init(context, width: 750, height: 1334); //flutter_screenuitl < 1.2
61+
ScreenUtil.init(width: 750, height: 1334); //flutter_screenuitl >= 1.2
5962
6063
//设置字体大小根据系统的“字体大小”辅助选项来进行缩放,默认为false
61-
ScreenUtil.init(context, width: 750, height: 1334, allowFontScaling: true);
64+
ScreenUtil.init(context, width: 750, height: 1334, allowFontScaling: true); //flutter_screenuitl < 1.2
65+
ScreenUtil.init(width: 750, height: 1334, allowFontScaling: true); //flutter_screenuitl >= 1.2
6266
6367
```
6468

@@ -198,9 +202,9 @@ class _MyHomePageState extends State<MyHomePage> {
198202
@override
199203
Widget build(BuildContext context) {
200204
//设置适配尺寸 (填入设计稿中设备的屏幕尺寸) 此处假如设计稿是按iPhone6的尺寸设计的(iPhone6 750*1334)
201-
ScreenUtil.init(context, width: 750, height: 1334, allowFontScaling: false);
202-
ScreenUtil.init(context);
203-
ScreenUtil.init(context, width: 750, height: 1334, allowFontScaling: false);
205+
ScreenUtil.init(width: 750, height: 1334, allowFontScaling: false);
206+
ScreenUtil.init();
207+
ScreenUtil.init(width: 750, height: 1334, allowFontScaling: false);
204208
205209
return ExampleWidget(title: 'FlutterScreenUtil示例');
206210
}
@@ -255,10 +259,10 @@ class _ExampleWidgetState extends State<ExampleWidget> {
255259
),
256260
],
257261
),
258-
Text('设备宽度:${ScreenUtil.screenWidth}px'),
259-
Text('设备高度:${ScreenUtil.screenHeight}px'),
260-
Text('设备宽度:${ScreenUtil.screenWidthDp}dp'),
261-
Text('设备高度:${ScreenUtil.screenHeightDp}dp'),
262+
Text('设备宽度:${ScreenUtil.screenWidth}dp'),
263+
Text('设备高度:${ScreenUtil.screenHeight}dp'),
264+
Text('设备宽度:${ScreenUtil.screenWidthPx}px'),
265+
Text('设备高度:${ScreenUtil.screenHeightPx}px'),
262266
Text('设备的像素密度:${ScreenUtil.pixelRatio}'),
263267
Text('底部安全区距离:${ScreenUtil.bottomBarHeight}dp'),
264268
Text('状态栏高度:${ScreenUtil.statusBarHeight}dp'),
@@ -295,8 +299,7 @@ class _ExampleWidgetState extends State<ExampleWidget> {
295299
floatingActionButton: FloatingActionButton(
296300
child: Icon(Icons.title),
297301
onPressed: () {
298-
ScreenUtil.init(context,
299-
width: 1500, height: 1334, allowFontScaling: false);
302+
ScreenUtil.init(width: 1500, height: 1334, allowFontScaling: false);
300303
setState(() {});
301304
},
302305
),
@@ -310,11 +313,10 @@ class _ExampleWidgetState extends State<ExampleWidget> {
310313
print(
311314
'底部安全区距离:${ScreenUtil.bottomBarHeight}dp'); //Bottom safe zone distance,suitable for buttons with full screen
312315
print(
313-
'状态栏高度:${ScreenUtil.statusBarHeight}dp'); //Status bar height , Notch will be higher Unit px
316+
'状态栏高度:${ScreenUtil.statusBarHeight}dp'); //状态栏高度 , 刘海屏会更高,单位dp
314317
315318
print('实际宽度的dp与设计稿px的比例:${ScreenUtil().scaleWidth}');
316319
print('实际高度的dp与设计稿px的比例:${ScreenUtil().scaleHeight}');
317-
318320
print(
319321
'宽度和字体相对于设计稿放大的比例:${ScreenUtil().scaleWidth * ScreenUtil.pixelRatio}');
320322
print('高度相对于设计稿放大的比例:${ScreenUtil().scaleHeight * ScreenUtil.pixelRatio}');

README_PT.md

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,13 @@ github: https://github.com/OpenFlutter/flutter_screenutil
1818

1919
### Adicionando a dependência:
2020
Por favor, verifique a última versão antes da instalação.
21+
Se houver algum problema com a nova versão, use a versão anterior
2122
```
2223
dependencies:
2324
flutter:
2425
sdk: flutter
2526
# add flutter_screenutil
26-
flutter_screenutil: ^1.0.2
27+
flutter_screenutil: ^2.0.0
2728
```
2829

2930
### Adicione o seguinte import em seu código Dart:
@@ -48,13 +49,16 @@ Certifique-se de definir as dimensões na paginal inicial do MaterialApp (ou sej
4849
//Preencha o tamanho da tela do dispositivo no protótipo de design
4950
5051
//Valor padrão: width : 1080px , height:1920px , allowFontScaling:false
51-
ScreenUtil.init(context);
52+
ScreenUtil.init(context); //flutter_screenuitl < 1.2
53+
ScreenUtil.init(); //flutter_screenuitl >= 1.2
5254
5355
//Se o design é baseado no iPhone6 ​​(iPhone6 ​​750*1334)
54-
ScreenUtil.init(context, width: 750, height: 1334);
56+
ScreenUtil.init(context, width: 750, height: 1334); //flutter_screenuitl < 1.2
57+
ScreenUtil.init(width: 750, height: 1334); //flutter_screenuitl >= 1.2
5558
5659
//Se você quer definir que o tamanho da fonte seja ajustado de acordo com a opção "tamanho da fonte" na acessibilidade do sistema
57-
ScreenUtil.init(context, width: 750, height: 1334, allowFontScaling: true);
60+
ScreenUtil.init(context, width: 750, height: 1334, allowFontScaling: true); //flutter_screenuitl < 1.2
61+
ScreenUtil.init(width: 750, height: 1334, allowFontScaling: true); //flutter_screenuitl >= 1.2
5862
5963
```
6064

@@ -182,7 +186,7 @@ import 'package:flutter_screenutil/flutter_screenutil.dart';
182186
@override
183187
Widget build(BuildContext context) {
184188
///Define o tamanho de ajuste (preenche o tamanho da tela do dispositivo no design). Se o design é baseado no tamanho do iPhone6 (iPhone6 ​​750*1334)
185-
ScreenUtil.init(context, width: 750, height: 1334, allowFontScaling: false);
189+
ScreenUtil.init(width: 750, height: 1334, allowFontScaling: false);
186190
187191
print('Largura do dispositivo:${ScreenUtil.screenWidth}'); //Largura do dispositivo
188192
print('Altura do dispositivo:${ScreenUtil.screenHeight}'); //Altura do dispositivo
@@ -235,11 +239,11 @@ import 'package:flutter_screenutil/flutter_screenutil.dart';
235239
),
236240
],
237241
),
238-
Text('Largura do dispositivo:${ScreenUtil.screenWidth}px'),
239-
Text('Altura do dispositivo:${ScreenUtil.screenHeight}px'),
242+
Text('Largura do dispositivo:${ScreenUtil.screenWidth}dp'),
243+
Text('Altura do dispositivo:${ScreenUtil.screenHeight}dp'),
240244
Text('Densidade de pixels do dispositivo:${ScreenUtil.pixelRatio}'),
241-
Text('Distância segura do rodapé:${ScreenUtil.bottomBarHeight}px'),
242-
Text('Altura da status bar:${ScreenUtil.statusBarHeight}px'),
245+
Text('Distância segura do rodapé:${ScreenUtil.bottomBarHeight}dp'),
246+
Text('Altura da status bar:${ScreenUtil.statusBarHeight}dp'),
243247
Text(
244248
'Razão entre a largura atual e a largura do protótipo de design em pixels:${ScreenUtil().scaleWidth}',
245249
textAlign: TextAlign.center,

example/android/build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ buildscript {
22
repositories {
33
google()
44
jcenter()
5+
maven { url "http://download.flutter.io" }
56
}
67

78
dependencies {
@@ -13,6 +14,7 @@ allprojects {
1314
repositories {
1415
google()
1516
jcenter()
17+
maven { url "http://download.flutter.io" }
1618
}
1719
}
1820

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
#!/bin/sh
22
# This is a generated file; do not edit or check into version control.
3-
export "FLUTTER_ROOT=D:\flutter"
4-
export "FLUTTER_APPLICATION_PATH=D:\Project\flutter_ScreenUtil\example"
3+
export "FLUTTER_ROOT=D:\Develop\flutter"
4+
export "FLUTTER_APPLICATION_PATH=D:\Develop\Project\flutter_screenutil\example"
55
export "FLUTTER_TARGET=lib\main.dart"
66
export "FLUTTER_BUILD_DIR=build"
77
export "SYMROOT=${SOURCE_ROOT}/../build\ios"
8-
export "FLUTTER_FRAMEWORK_DIR=D:\flutter\bin\cache\artifacts\engine\ios"
8+
export "OTHER_LDFLAGS=$(inherited) -framework Flutter"
9+
export "FLUTTER_FRAMEWORK_DIR=D:\Develop\flutter\bin\cache\artifacts\engine\ios"
910
export "FLUTTER_BUILD_NAME=1.0.0"
1011
export "FLUTTER_BUILD_NUMBER=1"

example/lib/main.dart

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class _MyHomePageState extends State<MyHomePage> {
2626
@override
2727
Widget build(BuildContext context) {
2828
//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)
29-
ScreenUtil.init(context, width: 750, height: 1334, allowFontScaling: false);
29+
ScreenUtil.init(width: 750, height: 1334, allowFontScaling: false);
3030

3131
return ExampleWidget(title: 'FlutterScreenUtil Demo');
3232
}
@@ -81,10 +81,10 @@ class _ExampleWidgetState extends State<ExampleWidget> {
8181
),
8282
],
8383
),
84-
Text('Device width:${ScreenUtil.screenWidth}px'),
85-
Text('Device height:${ScreenUtil.screenHeight}px'),
86-
Text('Device width:${ScreenUtil.screenWidthDp}dp'),
87-
Text('Device height:${ScreenUtil.screenHeightDp}dp'),
84+
Text('Device width:${ScreenUtil.screenWidthPx}px'),
85+
Text('Device height:${ScreenUtil.screenHeightPx}px'),
86+
Text('Device width:${ScreenUtil.screenWidth}dp'),
87+
Text('Device height:${ScreenUtil.screenHeight}dp'),
8888
Text('Device pixel density:${ScreenUtil.pixelRatio}'),
8989
Text('Bottom safe zone distance:${ScreenUtil.bottomBarHeight}dp'),
9090
Text('Status bar height:${ScreenUtil.statusBarHeight}dp'),
@@ -123,17 +123,16 @@ class _ExampleWidgetState extends State<ExampleWidget> {
123123
floatingActionButton: FloatingActionButton(
124124
child: Icon(Icons.title),
125125
onPressed: () {
126-
ScreenUtil.init(context,
127-
width: 1500, height: 1334, allowFontScaling: false);
126+
ScreenUtil.init(width: 1500, height: 1334, allowFontScaling: false);
128127
setState(() {});
129128
},
130129
),
131130
);
132131
}
133132

134133
void printScreenInformation() {
135-
print('Device width px:${ScreenUtil.screenWidth}'); //Device width
136-
print('Device height px:${ScreenUtil.screenHeight}'); //Device height
134+
print('Device width dp:${ScreenUtil.screenWidth}'); //Device width
135+
print('Device height dp:${ScreenUtil.screenHeight}'); //Device height
137136
print(
138137
'Device pixel density:${ScreenUtil.pixelRatio}'); //Device pixel density
139138
print(
@@ -148,5 +147,6 @@ class _ExampleWidgetState extends State<ExampleWidget> {
148147
'The ratio of font and width to the size of the design:${ScreenUtil().scaleWidth * ScreenUtil.pixelRatio}');
149148
print(
150149
'The ratio of height width to the size of the design:${ScreenUtil().scaleHeight * ScreenUtil.pixelRatio}');
150+
print('System font scaling:${ScreenUtil.textScaleFactor}');
151151
}
152152
}

example/lib/main_zh.dart

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class _MyHomePageState extends State<MyHomePage> {
3131
Widget build(BuildContext context) {
3232
//设置适配尺寸 (填入设计稿中设备的屏幕尺寸) 此处假如设计稿是按iPhone6的尺寸设计的(iPhone6 750*1334)
3333

34-
ScreenUtil.init(context, width: 750, height: 1334, allowFontScaling: false);
34+
ScreenUtil.init(width: 750, height: 1334, allowFontScaling: false);
3535

3636
return ExampleWidget(title: 'FlutterScreenUtil示例');
3737
}
@@ -86,10 +86,10 @@ class _ExampleWidgetState extends State<ExampleWidget> {
8686
),
8787
],
8888
),
89-
Text('设备宽度:${ScreenUtil.screenWidth}px'),
90-
Text('设备高度:${ScreenUtil.screenHeight}px'),
91-
Text('设备宽度:${ScreenUtil.screenWidthDp}dp'),
92-
Text('设备高度:${ScreenUtil.screenHeightDp}dp'),
89+
Text('设备宽度:${ScreenUtil.screenWidthPx}px'),
90+
Text('设备高度:${ScreenUtil.screenHeightPx}px'),
91+
Text('设备宽度:${ScreenUtil.screenWidth}dp'),
92+
Text('设备高度:${ScreenUtil.screenHeight}dp'),
9393
Text('设备的像素密度:${ScreenUtil.pixelRatio}'),
9494
Text('底部安全区距离:${ScreenUtil.bottomBarHeight}dp'),
9595
Text('状态栏高度:${ScreenUtil.statusBarHeight}dp'),
@@ -126,8 +126,7 @@ class _ExampleWidgetState extends State<ExampleWidget> {
126126
floatingActionButton: FloatingActionButton(
127127
child: Icon(Icons.title),
128128
onPressed: () {
129-
ScreenUtil.init(context,
130-
width: 1500, height: 1334, allowFontScaling: false);
129+
ScreenUtil.init(width: 1500, height: 1334, allowFontScaling: false);
131130
setState(() {});
132131
},
133132
),

0 commit comments

Comments
 (0)