李卓原

2.3

@@ -6,6 +6,9 @@ @@ -6,6 +6,9 @@
6 * @Description: Update log 6 * @Description: Update log
7 --> 7 -->
8 8
  9 +# 2.3.0
  10 +- We still need context to initialize, sorry.
  11 +
9 # 2.2.0 12 # 2.2.0
10 - add 'wp','hp'. Get the height/width of the screen proportionally 13 - add 'wp','hp'. Get the height/width of the screen proportionally
11 - For example: 0.5.wp : Half the width of the screen. 14 - For example: 0.5.wp : Half the width of the screen.
@@ -49,16 +49,16 @@ Be sure to set the page in the MaterialApp's home/initialRoute(ie the entry file @@ -49,16 +49,16 @@ Be sure to set the page in the MaterialApp's home/initialRoute(ie the entry file
49 //fill in the screen size of the device in the design 49 //fill in the screen size of the device in the design
50 50
51 //default value : width : 1080px , height:1920px , allowFontScaling:false 51 //default value : width : 1080px , height:1920px , allowFontScaling:false
52 -ScreenUtil.init(context); //flutter_screenuitl < 1.2  
53 -ScreenUtil.init(); //flutter_screenuitl >= 1.2 52 +ScreenUtil.init(context); ~~//flutter_screenuitl < 1.2~~
  53 +~~ScreenUtil.init(); //flutter_screenuitl >= 1.2~~
54 54
55 //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)
56 -ScreenUtil.init(context, width: 750, height: 1334); //flutter_screenuitl < 1.2  
57 -ScreenUtil.init(width: 750, height: 1334); //flutter_screenuitl >= 1.2 56 +ScreenUtil.init(context, width: 750, height: 1334); ~~//flutter_screenuitl < 1.2~~
  57 +~~ScreenUtil.init(width: 750, height: 1334); //flutter_screenuitl >= 1.2~~
58 58
59 //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
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 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~~
62 62
63 ``` 63 ```
64 64
@@ -53,16 +53,16 @@ import 'package:flutter_screenutil/flutter_screenutil.dart'; @@ -53,16 +53,16 @@ import 'package:flutter_screenutil/flutter_screenutil.dart';
53 //填入设计稿中设备的屏幕尺寸 53 //填入设计稿中设备的屏幕尺寸
54 54
55 //默认 width : 1080px , height:1920px , allowFontScaling:false 55 //默认 width : 1080px , height:1920px , allowFontScaling:false
56 -ScreenUtil.init(context); //flutter_screenuitl < 1.2  
57 -ScreenUtil.init(); //flutter_screenuitl >= 1.2 56 +ScreenUtil.init(context); ~~//flutter_screenuitl < 1.2~~
  57 +~~ScreenUtil.init(); //flutter_screenuitl >= 1.2~~
58 58
59 //假如设计稿是按iPhone6的尺寸设计的(iPhone6 750*1334) 59 //假如设计稿是按iPhone6的尺寸设计的(iPhone6 750*1334)
60 -ScreenUtil.init(context, width: 750, height: 1334); //flutter_screenuitl < 1.2  
61 -ScreenUtil.init(width: 750, height: 1334); //flutter_screenuitl >= 1.2 60 +ScreenUtil.init(context, width: 750, height: 1334); ~~//flutter_screenuitl < 1.2~~
  61 +~~ScreenUtil.init(width: 750, height: 1334); //flutter_screenuitl >= 1.2~~
62 62
63 //设置字体大小根据系统的“字体大小”辅助选项来进行缩放,默认为false 63 //设置字体大小根据系统的“字体大小”辅助选项来进行缩放,默认为false
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 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~~
66 66
67 ``` 67 ```
68 68
@@ -49,16 +49,16 @@ Certifique-se de definir as dimensões na paginal inicial do MaterialApp (ou sej @@ -49,16 +49,16 @@ Certifique-se de definir as dimensões na paginal inicial do MaterialApp (ou sej
49 //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
50 50
51 //Valor padrão: width : 1080px , height:1920px , allowFontScaling:false 51 //Valor padrão: width : 1080px , height:1920px , allowFontScaling:false
52 -ScreenUtil.init(context); //flutter_screenuitl < 1.2  
53 -ScreenUtil.init(); //flutter_screenuitl >= 1.2 52 +ScreenUtil.init(context); ~~//flutter_screenuitl < 1.2~~
  53 +~~ScreenUtil.init(); //flutter_screenuitl >= 1.2~~
54 54
55 //Se o design é baseado no iPhone6 ​​(iPhone6 ​​750*1334) 55 //Se o design é baseado no iPhone6 ​​(iPhone6 ​​750*1334)
56 -ScreenUtil.init(context, width: 750, height: 1334); //flutter_screenuitl < 1.2  
57 -ScreenUtil.init(width: 750, height: 1334); //flutter_screenuitl >= 1.2 56 +ScreenUtil.init(context, width: 750, height: 1334); ~~//flutter_screenuitl < 1.2~~
  57 +~~ScreenUtil.init(width: 750, height: 1334); //flutter_screenuitl >= 1.2~~
58 58
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 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
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 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~~
62 62
63 ``` 63 ```
64 64
1 org.gradle.jvmargs=-Xmx1536M 1 org.gradle.jvmargs=-Xmx1536M
2 android.enableR8=true 2 android.enableR8=true
  3 +android.useAndroidX=true
  4 +android.enableJetifier=true
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:\Develop\flutter"  
4 -export "FLUTTER_APPLICATION_PATH=D:\Develop\Project\flutter_screenutil\example"  
5 -export "FLUTTER_TARGET=lib\main.dart" 3 +export "FLUTTER_ROOT=/Users/lizhuoyuan/Development/flutter"
  4 +export "FLUTTER_APPLICATION_PATH=/Users/lizhuoyuan/Development/Project/flutter_screenutil/example"
  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"  
8 -export "OTHER_LDFLAGS=$(inherited) -framework Flutter"  
9 -export "FLUTTER_FRAMEWORK_DIR=D:\Develop\flutter\bin\cache\artifacts\engine\ios" 7 +export "SYMROOT=${SOURCE_ROOT}/../build/ios"
  8 +export "FLUTTER_FRAMEWORK_DIR=/Users/lizhuoyuan/Development/flutter/bin/cache/artifacts/engine/ios"
10 export "FLUTTER_BUILD_NAME=1.0.0" 9 export "FLUTTER_BUILD_NAME=1.0.0"
11 export "FLUTTER_BUILD_NUMBER=1" 10 export "FLUTTER_BUILD_NUMBER=1"
  1 +import 'dart:ui';
  2 +
1 import 'package:flutter/material.dart'; 3 import 'package:flutter/material.dart';
2 import 'package:flutter_screenutil/flutter_screenutil.dart'; 4 import 'package:flutter_screenutil/flutter_screenutil.dart';
3 5
@@ -26,7 +28,7 @@ class _MyHomePageState extends State<MyHomePage> { @@ -26,7 +28,7 @@ class _MyHomePageState extends State<MyHomePage> {
26 @override 28 @override
27 Widget build(BuildContext context) { 29 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) 30 //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(width: 750, height: 1334, allowFontScaling: false); 31 + ScreenUtil.init(context, width: 750, height: 1334, allowFontScaling: false);
30 32
31 return ExampleWidget(title: 'FlutterScreenUtil Demo'); 33 return ExampleWidget(title: 'FlutterScreenUtil Demo');
32 } 34 }
@@ -44,7 +46,7 @@ class ExampleWidget extends StatefulWidget { @@ -44,7 +46,7 @@ class ExampleWidget extends StatefulWidget {
44 class _ExampleWidgetState extends State<ExampleWidget> { 46 class _ExampleWidgetState extends State<ExampleWidget> {
45 @override 47 @override
46 Widget build(BuildContext context) { 48 Widget build(BuildContext context) {
47 - printScreenInformation(); 49 + //printScreenInformation();
48 return Scaffold( 50 return Scaffold(
49 appBar: AppBar( 51 appBar: AppBar(
50 title: Text(widget.title), 52 title: Text(widget.title),
@@ -123,7 +125,8 @@ class _ExampleWidgetState extends State<ExampleWidget> { @@ -123,7 +125,8 @@ class _ExampleWidgetState extends State<ExampleWidget> {
123 floatingActionButton: FloatingActionButton( 125 floatingActionButton: FloatingActionButton(
124 child: Icon(Icons.title), 126 child: Icon(Icons.title),
125 onPressed: () { 127 onPressed: () {
126 - ScreenUtil.init(width: 1500, height: 1334, allowFontScaling: false); 128 + ScreenUtil.init(context,
  129 + width: 1500, height: 1334, allowFontScaling: false);
127 setState(() {}); 130 setState(() {});
128 }, 131 },
129 ), 132 ),
@@ -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(width: 750, height: 1334, allowFontScaling: false); 34 + ScreenUtil.init(context,width: 750, height: 1334, allowFontScaling: false);
35 35
36 return ExampleWidget(title: 'FlutterScreenUtil示例'); 36 return ExampleWidget(title: 'FlutterScreenUtil示例');
37 } 37 }
@@ -126,7 +126,7 @@ class _ExampleWidgetState extends State<ExampleWidget> { @@ -126,7 +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(width: 1500, height: 1334, allowFontScaling: false); 129 + ScreenUtil.init(context,width: 1500, height: 1334, allowFontScaling: false);
130 setState(() {}); 130 setState(() {});
131 }, 131 },
132 ), 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 'dart:ui'; 6 +import 'package:flutter/material.dart';
7 7
8 class ScreenUtil { 8 class ScreenUtil {
9 static ScreenUtil _instance; 9 static ScreenUtil _instance;
@@ -32,7 +32,7 @@ class ScreenUtil { @@ -32,7 +32,7 @@ class ScreenUtil {
32 return _instance; 32 return _instance;
33 } 33 }
34 34
35 - static void init( 35 + static void init(BuildContext context,
36 {num width = defaultWidth, 36 {num width = defaultWidth,
37 num height = defaultHeight, 37 num height = defaultHeight,
38 bool allowFontScaling = false}) { 38 bool allowFontScaling = false}) {
@@ -42,12 +42,14 @@ class ScreenUtil { @@ -42,12 +42,14 @@ class ScreenUtil {
42 _instance.uiWidthPx = width; 42 _instance.uiWidthPx = width;
43 _instance.uiHeightPx = height; 43 _instance.uiHeightPx = height;
44 _instance.allowFontScaling = allowFontScaling; 44 _instance.allowFontScaling = allowFontScaling;
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; 45 +
  46 + MediaQueryData mediaQuery = MediaQuery.of(context);
  47 + _pixelRatio = mediaQuery.devicePixelRatio;
  48 + _screenWidth = mediaQuery.size.width;
  49 + _screenHeight = mediaQuery.size.height;
  50 + _statusBarHeight = mediaQuery.padding.top;
  51 + _bottomBarHeight = mediaQuery.padding.bottom;
  52 + _textScaleFactor = mediaQuery.textScaleFactor;
51 } 53 }
52 54
53 /// 每个逻辑像素的字体像素数,字体的缩放比例 55 /// 每个逻辑像素的字体像素数,字体的缩放比例
@@ -60,27 +62,23 @@ class ScreenUtil { @@ -60,27 +62,23 @@ class ScreenUtil {
60 62
61 /// 当前设备宽度 dp 63 /// 当前设备宽度 dp
62 /// The horizontal extent of this size. 64 /// The horizontal extent of this size.
63 - static double get screenWidth => _screenWidth / _pixelRatio; 65 + static double get screenWidth => _screenWidth;
64 66
65 ///当前设备高度 dp 67 ///当前设备高度 dp
66 ///The vertical extent of this size. dp 68 ///The vertical extent of this size. dp
67 - static double get screenHeight => _screenHeight / _pixelRatio; 69 + static double get screenHeight => _screenHeight;
68 70
69 /// 当前设备宽度 px 71 /// 当前设备宽度 px
70 /// The vertical extent of this size. px 72 /// The vertical extent of this size. px
71 - static double get screenWidthPx => _screenWidth; 73 + static double get screenWidthPx => _screenWidth * _pixelRatio;
72 74
73 /// 当前设备高度 px 75 /// 当前设备高度 px
74 /// The vertical extent of this size. px 76 /// The vertical extent of this size. px
75 - static double get screenHeightPx => _screenHeight;  
76 -  
77 - /// 状态栏高度 dp 刘海屏会更高  
78 - /// The offset from the top  
79 - static double get statusBarHeight => _statusBarHeight / _pixelRatio; 77 + static double get screenHeightPx => _screenHeight * _pixelRatio;
80 78
81 /// 状态栏高度 dp 刘海屏会更高 79 /// 状态栏高度 dp 刘海屏会更高
82 /// The offset from the top 80 /// The offset from the top
83 - static double get statusBarHeightPx => _statusBarHeight; 81 + static double get statusBarHeight => _statusBarHeight;
84 82
85 /// 底部安全区距离 dp 83 /// 底部安全区距离 dp
86 /// The offset from the bottom. 84 /// The offset from the bottom.
@@ -88,9 +86,9 @@ class ScreenUtil { @@ -88,9 +86,9 @@ class ScreenUtil {
88 86
89 /// 实际的dp与UI设计px的比例 87 /// 实际的dp与UI设计px的比例
90 /// The ratio of the actual dp to the design draft px 88 /// The ratio of the actual dp to the design draft px
91 - double get scaleWidth => screenWidth / uiWidthPx; 89 + double get scaleWidth => _screenWidth / uiWidthPx;
92 90
93 - double get scaleHeight => screenHeight / uiHeightPx; 91 + double get scaleHeight => _screenHeight / uiHeightPx;
94 92
95 double get scaleText => scaleWidth; 93 double get scaleText => scaleWidth;
96 94
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: 2.2.0 3 +version: 2.3.0
4 homepage: https://github.com/OpenFlutter/flutter_screenutil 4 homepage: https://github.com/OpenFlutter/flutter_screenutil
5 5
6 environment: 6 environment: