LiZhuoyuan

2.0.0

@@ -2,10 +2,14 @@ @@ -2,10 +2,14 @@
2 * @Author: zhuoyuan93@gmail.com 2 * @Author: zhuoyuan93@gmail.com
3 * @Date: 2018-10-16 19:43:03 3 * @Date: 2018-10-16 19:43:03
4 * @LastEditors: zhuoyuan93@gmail.com 4 * @LastEditors: zhuoyuan93@gmail.com
5 - * @LastEditTime: 2020年1月14日 12:11:02 5 + * @LastEditTime: 2020年6月20日 11:20:02
6 * @Description: Update log 6 * @Description: Update log
7 --> 7 -->
8 8
  9 +#2.0.0
  10 +- Use `MediaQueryData.fromWindow(window)` instead of `MediaQuery.of(context)`, no context parameter required
  11 +- API changes, please note
  12 +
9 #1.1.0 13 #1.1.0
10 - support ExtensionMethod Dart-SDK-2.6.0 14 - support ExtensionMethod Dart-SDK-2.6.0
11 - you can use 'width: 50.w' instead of 'width: ScreenUtil().setWidth(50)' 15 - you can use 'width: 50.w' instead of 'width: ScreenUtil().setWidth(50)'
@@ -18,12 +18,13 @@ github: https://github.com/OpenFlutter/flutter_screenutil @@ -18,12 +18,13 @@ github: https://github.com/OpenFlutter/flutter_screenutil
18 18
19 ### Add dependency: 19 ### Add dependency:
20 Please check the latest version before installation. 20 Please check the latest version before installation.
  21 +If there is any problem with the new version, please use the previous version
21 ``` 22 ```
22 dependencies: 23 dependencies:
23 flutter: 24 flutter:
24 sdk: flutter 25 sdk: flutter
25 # add flutter_screenutil 26 # add flutter_screenutil
26 - flutter_screenutil: ^1.0.2 27 + flutter_screenutil: ^2.0.0
27 ``` 28 ```
28 29
29 ### Add the following imports to your Dart code: 30 ### 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 @@ -48,13 +49,16 @@ Be sure to set the page in the MaterialApp's home(ie the entry file, just set it
48 //fill in the screen size of the device in the design 49 //fill in the screen size of the device in the design
49 50
50 //default value : width : 1080px , height:1920px , allowFontScaling:false 51 //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
52 54
53 //If the design is based on the size of the iPhone6 ​​(iPhone6 ​​750*1334) 55 //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
55 58
56 //If you want to set the font size is scaled according to the system's "font size" assist option 59 //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
58 62
59 ``` 63 ```
60 64
@@ -189,7 +193,7 @@ class _MyHomePageState extends State<MyHomePage> { @@ -189,7 +193,7 @@ class _MyHomePageState extends State<MyHomePage> {
189 @override 193 @override
190 Widget build(BuildContext context) { 194 Widget build(BuildContext context) {
191 //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) 195 //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);
193 197
194 return ExampleWidget(title: 'FlutterScreenUtil Demo'); 198 return ExampleWidget(title: 'FlutterScreenUtil Demo');
195 } 199 }
@@ -244,10 +248,10 @@ class _ExampleWidgetState extends State<ExampleWidget> { @@ -244,10 +248,10 @@ class _ExampleWidgetState extends State<ExampleWidget> {
244 ), 248 ),
245 ], 249 ],
246 ), 250 ),
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'),
251 Text('Device pixel density:${ScreenUtil.pixelRatio}'), 255 Text('Device pixel density:${ScreenUtil.pixelRatio}'),
252 Text('Bottom safe zone distance:${ScreenUtil.bottomBarHeight}dp'), 256 Text('Bottom safe zone distance:${ScreenUtil.bottomBarHeight}dp'),
253 Text('Status bar height:${ScreenUtil.statusBarHeight}dp'), 257 Text('Status bar height:${ScreenUtil.statusBarHeight}dp'),
@@ -286,8 +290,7 @@ class _ExampleWidgetState extends State<ExampleWidget> { @@ -286,8 +290,7 @@ class _ExampleWidgetState extends State<ExampleWidget> {
286 floatingActionButton: FloatingActionButton( 290 floatingActionButton: FloatingActionButton(
287 child: Icon(Icons.title), 291 child: Icon(Icons.title),
288 onPressed: () { 292 onPressed: () {
289 - ScreenUtil.init(context,  
290 - width: 1500, height: 1334, allowFontScaling: false); 293 + ScreenUtil.init(width: 1500, height: 1334, allowFontScaling: false);
291 setState(() {}); 294 setState(() {});
292 }, 295 },
293 ), 296 ),
@@ -302,7 +305,7 @@ class _ExampleWidgetState extends State<ExampleWidget> { @@ -302,7 +305,7 @@ class _ExampleWidgetState extends State<ExampleWidget> {
302 print( 305 print(
303 'Bottom safe zone distance dp:${ScreenUtil.bottomBarHeight}'); //Bottom safe zone distance,suitable for buttons with full screen 306 'Bottom safe zone distance dp:${ScreenUtil.bottomBarHeight}'); //Bottom safe zone distance,suitable for buttons with full screen
304 print( 307 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
306 print( 309 print(
307 'Ratio of actual width dp to design draft px:${ScreenUtil().scaleWidth}'); 310 'Ratio of actual width dp to design draft px:${ScreenUtil().scaleWidth}');
308 print( 311 print(
@@ -23,12 +23,13 @@ csdn博客工具介绍:https://blog.csdn.net/u011272795/article/details/82795477 @@ -23,12 +23,13 @@ csdn博客工具介绍:https://blog.csdn.net/u011272795/article/details/82795477
23 ### 安装依赖: 23 ### 安装依赖:
24 24
25 安装之前请查看最新版本 25 安装之前请查看最新版本
  26 +新版本如有问题请使用上一版
26 ``` 27 ```
27 dependencies: 28 dependencies:
28 flutter: 29 flutter:
29 sdk: flutter 30 sdk: flutter
30 # 添加依赖 31 # 添加依赖
31 - flutter_screenutil: ^1.0.2 32 + flutter_screenutil: ^2.0.0
32 ``` 33 ```
33 34
34 ### 在每个使用的地方导入包: 35 ### 在每个使用的地方导入包:
@@ -52,13 +53,16 @@ import 'package:flutter_screenutil/flutter_screenutil.dart'; @@ -52,13 +53,16 @@ import 'package:flutter_screenutil/flutter_screenutil.dart';
52 //填入设计稿中设备的屏幕尺寸 53 //填入设计稿中设备的屏幕尺寸
53 54
54 //默认 width : 1080px , height:1920px , allowFontScaling:false 55 //默认 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
56 58
57 //假如设计稿是按iPhone6的尺寸设计的(iPhone6 750*1334) 59 //假如设计稿是按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
59 62
60 //设置字体大小根据系统的“字体大小”辅助选项来进行缩放,默认为false 63 //设置字体大小根据系统的“字体大小”辅助选项来进行缩放,默认为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
62 66
63 ``` 67 ```
64 68
@@ -198,9 +202,9 @@ class _MyHomePageState extends State<MyHomePage> { @@ -198,9 +202,9 @@ class _MyHomePageState extends State<MyHomePage> {
198 @override 202 @override
199 Widget build(BuildContext context) { 203 Widget build(BuildContext context) {
200 //设置适配尺寸 (填入设计稿中设备的屏幕尺寸) 此处假如设计稿是按iPhone6的尺寸设计的(iPhone6 750*1334) 204 //设置适配尺寸 (填入设计稿中设备的屏幕尺寸) 此处假如设计稿是按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);
204 208
205 return ExampleWidget(title: 'FlutterScreenUtil示例'); 209 return ExampleWidget(title: 'FlutterScreenUtil示例');
206 } 210 }
@@ -255,10 +259,10 @@ class _ExampleWidgetState extends State<ExampleWidget> { @@ -255,10 +259,10 @@ class _ExampleWidgetState extends State<ExampleWidget> {
255 ), 259 ),
256 ], 260 ],
257 ), 261 ),
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'),
262 Text('设备的像素密度:${ScreenUtil.pixelRatio}'), 266 Text('设备的像素密度:${ScreenUtil.pixelRatio}'),
263 Text('底部安全区距离:${ScreenUtil.bottomBarHeight}dp'), 267 Text('底部安全区距离:${ScreenUtil.bottomBarHeight}dp'),
264 Text('状态栏高度:${ScreenUtil.statusBarHeight}dp'), 268 Text('状态栏高度:${ScreenUtil.statusBarHeight}dp'),
@@ -295,8 +299,7 @@ class _ExampleWidgetState extends State<ExampleWidget> { @@ -295,8 +299,7 @@ class _ExampleWidgetState extends State<ExampleWidget> {
295 floatingActionButton: FloatingActionButton( 299 floatingActionButton: FloatingActionButton(
296 child: Icon(Icons.title), 300 child: Icon(Icons.title),
297 onPressed: () { 301 onPressed: () {
298 - ScreenUtil.init(context,  
299 - width: 1500, height: 1334, allowFontScaling: false); 302 + ScreenUtil.init(width: 1500, height: 1334, allowFontScaling: false);
300 setState(() {}); 303 setState(() {});
301 }, 304 },
302 ), 305 ),
@@ -310,11 +313,10 @@ class _ExampleWidgetState extends State<ExampleWidget> { @@ -310,11 +313,10 @@ class _ExampleWidgetState extends State<ExampleWidget> {
310 print( 313 print(
311 '底部安全区距离:${ScreenUtil.bottomBarHeight}dp'); //Bottom safe zone distance,suitable for buttons with full screen 314 '底部安全区距离:${ScreenUtil.bottomBarHeight}dp'); //Bottom safe zone distance,suitable for buttons with full screen
312 print( 315 print(
313 - '状态栏高度:${ScreenUtil.statusBarHeight}dp'); //Status bar height , Notch will be higher Unit px 316 + '状态栏高度:${ScreenUtil.statusBarHeight}dp'); //状态栏高度 , 刘海屏会更高,单位dp
314 317
315 print('实际宽度的dp与设计稿px的比例:${ScreenUtil().scaleWidth}'); 318 print('实际宽度的dp与设计稿px的比例:${ScreenUtil().scaleWidth}');
316 print('实际高度的dp与设计稿px的比例:${ScreenUtil().scaleHeight}'); 319 print('实际高度的dp与设计稿px的比例:${ScreenUtil().scaleHeight}');
317 -  
318 print( 320 print(
319 '宽度和字体相对于设计稿放大的比例:${ScreenUtil().scaleWidth * ScreenUtil.pixelRatio}'); 321 '宽度和字体相对于设计稿放大的比例:${ScreenUtil().scaleWidth * ScreenUtil.pixelRatio}');
320 print('高度相对于设计稿放大的比例:${ScreenUtil().scaleHeight * ScreenUtil.pixelRatio}'); 322 print('高度相对于设计稿放大的比例:${ScreenUtil().scaleHeight * ScreenUtil.pixelRatio}');
@@ -18,12 +18,13 @@ github: https://github.com/OpenFlutter/flutter_screenutil @@ -18,12 +18,13 @@ github: https://github.com/OpenFlutter/flutter_screenutil
18 18
19 ### Adicionando a dependência: 19 ### Adicionando a dependência:
20 Por favor, verifique a última versão antes da instalação. 20 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
21 ``` 22 ```
22 dependencies: 23 dependencies:
23 flutter: 24 flutter:
24 sdk: flutter 25 sdk: flutter
25 # add flutter_screenutil 26 # add flutter_screenutil
26 - flutter_screenutil: ^1.0.2 27 + flutter_screenutil: ^2.0.0
27 ``` 28 ```
28 29
29 ### Adicione o seguinte import em seu código Dart: 30 ### 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 @@ -48,13 +49,16 @@ Certifique-se de definir as dimensões na paginal inicial do MaterialApp (ou sej
48 //Preencha o tamanho da tela do dispositivo no protótipo de design 49 //Preencha o tamanho da tela do dispositivo no protótipo de design
49 50
50 //Valor padrão: width : 1080px , height:1920px , allowFontScaling:false 51 //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
52 54
53 //Se o design é baseado no iPhone6 ​​(iPhone6 ​​750*1334) 55 //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
55 58
56 //Se você quer definir que o tamanho da fonte seja ajustado de acordo com a opção "tamanho da fonte" na acessibilidade do sistema 59 //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
58 62
59 ``` 63 ```
60 64
@@ -182,7 +186,7 @@ import 'package:flutter_screenutil/flutter_screenutil.dart'; @@ -182,7 +186,7 @@ import 'package:flutter_screenutil/flutter_screenutil.dart';
182 @override 186 @override
183 Widget build(BuildContext context) { 187 Widget build(BuildContext context) {
184 ///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) 188 ///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);
186 190
187 print('Largura do dispositivo:${ScreenUtil.screenWidth}'); //Largura do dispositivo 191 print('Largura do dispositivo:${ScreenUtil.screenWidth}'); //Largura do dispositivo
188 print('Altura do dispositivo:${ScreenUtil.screenHeight}'); //Altura do dispositivo 192 print('Altura do dispositivo:${ScreenUtil.screenHeight}'); //Altura do dispositivo
@@ -235,11 +239,11 @@ import 'package:flutter_screenutil/flutter_screenutil.dart'; @@ -235,11 +239,11 @@ import 'package:flutter_screenutil/flutter_screenutil.dart';
235 ), 239 ),
236 ], 240 ],
237 ), 241 ),
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'),
240 Text('Densidade de pixels do dispositivo:${ScreenUtil.pixelRatio}'), 244 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'),
243 Text( 247 Text(
244 'Razão entre a largura atual e a largura do protótipo de design em pixels:${ScreenUtil().scaleWidth}', 248 'Razão entre a largura atual e a largura do protótipo de design em pixels:${ScreenUtil().scaleWidth}',
245 textAlign: TextAlign.center, 249 textAlign: TextAlign.center,
@@ -2,6 +2,7 @@ buildscript { @@ -2,6 +2,7 @@ buildscript {
2 repositories { 2 repositories {
3 google() 3 google()
4 jcenter() 4 jcenter()
  5 + maven { url "http://download.flutter.io" }
5 } 6 }
6 7
7 dependencies { 8 dependencies {
@@ -13,6 +14,7 @@ allprojects { @@ -13,6 +14,7 @@ allprojects {
13 repositories { 14 repositories {
14 google() 15 google()
15 jcenter() 16 jcenter()
  17 + maven { url "http://download.flutter.io" }
16 } 18 }
17 } 19 }
18 20
1 #!/bin/sh 1 #!/bin/sh
2 # This is a generated file; do not edit or check into version control. 2 # 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"
5 export "FLUTTER_TARGET=lib\main.dart" 5 export "FLUTTER_TARGET=lib\main.dart"
6 export "FLUTTER_BUILD_DIR=build" 6 export "FLUTTER_BUILD_DIR=build"
7 export "SYMROOT=${SOURCE_ROOT}/../build\ios" 7 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"
9 export "FLUTTER_BUILD_NAME=1.0.0" 10 export "FLUTTER_BUILD_NAME=1.0.0"
10 export "FLUTTER_BUILD_NUMBER=1" 11 export "FLUTTER_BUILD_NUMBER=1"
@@ -26,7 +26,7 @@ class _MyHomePageState extends State<MyHomePage> { @@ -26,7 +26,7 @@ class _MyHomePageState extends State<MyHomePage> {
26 @override 26 @override
27 Widget build(BuildContext context) { 27 Widget build(BuildContext context) {
28 //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) 28 //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);
30 30
31 return ExampleWidget(title: 'FlutterScreenUtil Demo'); 31 return ExampleWidget(title: 'FlutterScreenUtil Demo');
32 } 32 }
@@ -81,10 +81,10 @@ class _ExampleWidgetState extends State<ExampleWidget> { @@ -81,10 +81,10 @@ class _ExampleWidgetState extends State<ExampleWidget> {
81 ), 81 ),
82 ], 82 ],
83 ), 83 ),
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'),
88 Text('Device pixel density:${ScreenUtil.pixelRatio}'), 88 Text('Device pixel density:${ScreenUtil.pixelRatio}'),
89 Text('Bottom safe zone distance:${ScreenUtil.bottomBarHeight}dp'), 89 Text('Bottom safe zone distance:${ScreenUtil.bottomBarHeight}dp'),
90 Text('Status bar height:${ScreenUtil.statusBarHeight}dp'), 90 Text('Status bar height:${ScreenUtil.statusBarHeight}dp'),
@@ -123,8 +123,7 @@ class _ExampleWidgetState extends State<ExampleWidget> { @@ -123,8 +123,7 @@ class _ExampleWidgetState extends State<ExampleWidget> {
123 floatingActionButton: FloatingActionButton( 123 floatingActionButton: FloatingActionButton(
124 child: Icon(Icons.title), 124 child: Icon(Icons.title),
125 onPressed: () { 125 onPressed: () {
126 - ScreenUtil.init(context,  
127 - width: 1500, height: 1334, allowFontScaling: false); 126 + ScreenUtil.init(width: 1500, height: 1334, allowFontScaling: false);
128 setState(() {}); 127 setState(() {});
129 }, 128 },
130 ), 129 ),
@@ -132,8 +131,8 @@ class _ExampleWidgetState extends State<ExampleWidget> { @@ -132,8 +131,8 @@ class _ExampleWidgetState extends State<ExampleWidget> {
132 } 131 }
133 132
134 void printScreenInformation() { 133 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
137 print( 136 print(
138 'Device pixel density:${ScreenUtil.pixelRatio}'); //Device pixel density 137 'Device pixel density:${ScreenUtil.pixelRatio}'); //Device pixel density
139 print( 138 print(
@@ -148,5 +147,6 @@ class _ExampleWidgetState extends State<ExampleWidget> { @@ -148,5 +147,6 @@ class _ExampleWidgetState extends State<ExampleWidget> {
148 'The ratio of font and width to the size of the design:${ScreenUtil().scaleWidth * ScreenUtil.pixelRatio}'); 147 'The ratio of font and width to the size of the design:${ScreenUtil().scaleWidth * ScreenUtil.pixelRatio}');
149 print( 148 print(
150 'The ratio of height width to the size of the design:${ScreenUtil().scaleHeight * ScreenUtil.pixelRatio}'); 149 'The ratio of height width to the size of the design:${ScreenUtil().scaleHeight * ScreenUtil.pixelRatio}');
  150 + print('System font scaling:${ScreenUtil.textScaleFactor}');
151 } 151 }
152 } 152 }
@@ -31,7 +31,7 @@ class _MyHomePageState extends State<MyHomePage> { @@ -31,7 +31,7 @@ class _MyHomePageState extends State<MyHomePage> {
31 Widget build(BuildContext context) { 31 Widget build(BuildContext context) {
32 //设置适配尺寸 (填入设计稿中设备的屏幕尺寸) 此处假如设计稿是按iPhone6的尺寸设计的(iPhone6 750*1334) 32 //设置适配尺寸 (填入设计稿中设备的屏幕尺寸) 此处假如设计稿是按iPhone6的尺寸设计的(iPhone6 750*1334)
33 33
34 - ScreenUtil.init(context, width: 750, height: 1334, allowFontScaling: false); 34 + ScreenUtil.init(width: 750, height: 1334, allowFontScaling: false);
35 35
36 return ExampleWidget(title: 'FlutterScreenUtil示例'); 36 return ExampleWidget(title: 'FlutterScreenUtil示例');
37 } 37 }
@@ -86,10 +86,10 @@ class _ExampleWidgetState extends State<ExampleWidget> { @@ -86,10 +86,10 @@ class _ExampleWidgetState extends State<ExampleWidget> {
86 ), 86 ),
87 ], 87 ],
88 ), 88 ),
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'),
93 Text('设备的像素密度:${ScreenUtil.pixelRatio}'), 93 Text('设备的像素密度:${ScreenUtil.pixelRatio}'),
94 Text('底部安全区距离:${ScreenUtil.bottomBarHeight}dp'), 94 Text('底部安全区距离:${ScreenUtil.bottomBarHeight}dp'),
95 Text('状态栏高度:${ScreenUtil.statusBarHeight}dp'), 95 Text('状态栏高度:${ScreenUtil.statusBarHeight}dp'),
@@ -126,8 +126,7 @@ class _ExampleWidgetState extends State<ExampleWidget> { @@ -126,8 +126,7 @@ class _ExampleWidgetState extends State<ExampleWidget> {
126 floatingActionButton: FloatingActionButton( 126 floatingActionButton: FloatingActionButton(
127 child: Icon(Icons.title), 127 child: Icon(Icons.title),
128 onPressed: () { 128 onPressed: () {
129 - ScreenUtil.init(context,  
130 - width: 1500, height: 1334, allowFontScaling: false); 129 + ScreenUtil.init(width: 1500, height: 1334, allowFontScaling: false);
131 setState(() {}); 130 setState(() {});
132 }, 131 },
133 ), 132 ),
@@ -3,7 +3,7 @@ @@ -3,7 +3,7 @@
3 * email: zhuoyuan93@gmail.com 3 * email: zhuoyuan93@gmail.com
4 */ 4 */
5 5
6 -import 'package:flutter/material.dart'; 6 +import 'dart:ui';
7 7
8 class ScreenUtil { 8 class ScreenUtil {
9 static ScreenUtil _instance; 9 static ScreenUtil _instance;
@@ -19,7 +19,6 @@ class ScreenUtil { @@ -19,7 +19,6 @@ class ScreenUtil {
19 /// allowFontScaling Specifies whether fonts should scale to respect Text Size accessibility settings. The default is false. 19 /// allowFontScaling Specifies whether fonts should scale to respect Text Size accessibility settings. The default is false.
20 bool allowFontScaling; 20 bool allowFontScaling;
21 21
22 - static MediaQueryData _mediaQueryData;  
23 static double _screenWidth; 22 static double _screenWidth;
24 static double _screenHeight; 23 static double _screenHeight;
25 static double _pixelRatio; 24 static double _pixelRatio;
@@ -33,7 +32,7 @@ class ScreenUtil { @@ -33,7 +32,7 @@ class ScreenUtil {
33 return _instance; 32 return _instance;
34 } 33 }
35 34
36 - static void init(BuildContext context, 35 + static void init(
37 {num width = defaultWidth, 36 {num width = defaultWidth,
38 num height = defaultHeight, 37 num height = defaultHeight,
39 bool allowFontScaling = false}) { 38 bool allowFontScaling = false}) {
@@ -43,19 +42,14 @@ class ScreenUtil { @@ -43,19 +42,14 @@ class ScreenUtil {
43 _instance.uiWidthPx = width; 42 _instance.uiWidthPx = width;
44 _instance.uiHeightPx = height; 43 _instance.uiHeightPx = height;
45 _instance.allowFontScaling = allowFontScaling; 44 _instance.allowFontScaling = allowFontScaling;
46 -  
47 - MediaQueryData mediaQuery = MediaQuery.of(context);  
48 - _mediaQueryData = mediaQuery;  
49 - _pixelRatio = mediaQuery.devicePixelRatio;  
50 - _screenWidth = mediaQuery.size.width;  
51 - _screenHeight = mediaQuery.size.height;  
52 - _statusBarHeight = mediaQuery.padding.top;  
53 - _bottomBarHeight = _mediaQueryData.padding.bottom;  
54 - _textScaleFactor = mediaQuery.textScaleFactor; 45 + _pixelRatio = window.devicePixelRatio;
  46 + _screenWidth = window.physicalSize.width;
  47 + _screenHeight = window.physicalSize.height;
  48 + _statusBarHeight = window.padding.top;
  49 + _bottomBarHeight = window.padding.bottom;
  50 + _textScaleFactor = window.textScaleFactor;
55 } 51 }
56 52
57 - static MediaQueryData get mediaQueryData => _mediaQueryData;  
58 -  
59 /// 每个逻辑像素的字体像素数,字体的缩放比例 53 /// 每个逻辑像素的字体像素数,字体的缩放比例
60 /// The number of font pixels for each logical pixel. 54 /// The number of font pixels for each logical pixel.
61 static double get textScaleFactor => _textScaleFactor; 55 static double get textScaleFactor => _textScaleFactor;
@@ -66,23 +60,27 @@ class ScreenUtil { @@ -66,23 +60,27 @@ class ScreenUtil {
66 60
67 /// 当前设备宽度 dp 61 /// 当前设备宽度 dp
68 /// The horizontal extent of this size. 62 /// The horizontal extent of this size.
69 - static double get screenWidthDp => _screenWidth; 63 + static double get screenWidth => _screenWidth / _pixelRatio;
70 64
71 ///当前设备高度 dp 65 ///当前设备高度 dp
72 ///The vertical extent of this size. dp 66 ///The vertical extent of this size. dp
73 - static double get screenHeightDp => _screenHeight; 67 + static double get screenHeight => _screenHeight / _pixelRatio;
74 68
75 /// 当前设备宽度 px 69 /// 当前设备宽度 px
76 /// The vertical extent of this size. px 70 /// The vertical extent of this size. px
77 - static double get screenWidth => _screenWidth * _pixelRatio; 71 + static double get screenWidthPx => _screenWidth;
78 72
79 /// 当前设备高度 px 73 /// 当前设备高度 px
80 /// The vertical extent of this size. px 74 /// The vertical extent of this size. px
81 - static double get screenHeight => _screenHeight * _pixelRatio; 75 + static double get screenHeightPx => _screenHeight;
  76 +
  77 + /// 状态栏高度 dp 刘海屏会更高
  78 + /// The offset from the top
  79 + static double get statusBarHeight => _statusBarHeight / _pixelRatio;
82 80
83 /// 状态栏高度 dp 刘海屏会更高 81 /// 状态栏高度 dp 刘海屏会更高
84 /// The offset from the top 82 /// The offset from the top
85 - static double get statusBarHeight => _statusBarHeight; 83 + static double get statusBarHeightPx => _statusBarHeight;
86 84
87 /// 底部安全区距离 dp 85 /// 底部安全区距离 dp
88 /// The offset from the bottom. 86 /// The offset from the bottom.
@@ -90,9 +88,9 @@ class ScreenUtil { @@ -90,9 +88,9 @@ class ScreenUtil {
90 88
91 /// 实际的dp与UI设计px的比例 89 /// 实际的dp与UI设计px的比例
92 /// The ratio of the actual dp to the design draft px 90 /// The ratio of the actual dp to the design draft px
93 - double get scaleWidth => _screenWidth / uiWidthPx; 91 + double get scaleWidth => screenWidth / uiWidthPx;
94 92
95 - double get scaleHeight => _screenHeight / uiHeightPx; 93 + double get scaleHeight => screenHeight / uiHeightPx;
96 94
97 double get scaleText => scaleWidth; 95 double get scaleText => scaleWidth;
98 96
1 name: flutter_screenutil 1 name: flutter_screenutil
2 description: A flutter plugin for adapting screen and font size.Guaranteed to look good on different models 2 description: A flutter plugin for adapting screen and font size.Guaranteed to look good on different models
3 -version: 1.1.0 3 +version: 2.0.0
4 homepage: https://github.com/OpenFlutter/flutter_screenutil 4 homepage: https://github.com/OpenFlutter/flutter_screenutil
5 5
6 environment: 6 environment: