LiZhuoyuan
Committed by GitHub

Merge pull request #138 from sarbagyastha/master

No need of BuildContext for initialization
@@ -5,7 +5,12 @@ @@ -5,7 +5,12 @@
5 * @LastEditTime: 2020年6月20日 11:20:02 5 * @LastEditTime: 2020年6月20日 11:20:02
6 * @Description: Update log 6 * @Description: Update log
7 --> 7 -->
8 - 8 +# 3.0.0-beta.1
  9 +**BREAKING CHANGES**
  10 +- `BuildContext` is no more required while initializing. i.e. ScreenUtil.init(~~context~~)
  11 +- Initialize size of design draft using `designSize` instead of width & height.
  12 +- All the static methods are now member methods.
  13 +
9 # 2.3.1 14 # 2.3.1
10 - add textStyle Example. 15 - add textStyle Example.
11 16
  1 +# This branch is suitable for the beta version of flutter
1 2
2 # flutter_screenutil 3 # flutter_screenutil
3 [![pub package](https://img.shields.io/pub/v/flutter_screenutil.svg)](https://pub.dartlang.org/packages/flutter_screenutil) 4 [![pub package](https://img.shields.io/pub/v/flutter_screenutil.svg)](https://pub.dartlang.org/packages/flutter_screenutil)
@@ -14,6 +15,9 @@ @@ -14,6 +15,9 @@
14 15
15 [Update log](https://github.com/OpenFlutter/flutter_screenutil/blob/master/CHANGELOG.md) 16 [Update log](https://github.com/OpenFlutter/flutter_screenutil/blob/master/CHANGELOG.md)
16 17
  18 +## Note
  19 +v3 requires `flutter >= 1.19.0`. Use v2 for current stable version of flutter.
  20 +
17 ## Usage: 21 ## Usage:
18 22
19 ### Add dependency: 23 ### Add dependency:
@@ -24,7 +28,7 @@ dependencies: @@ -24,7 +28,7 @@ dependencies:
24 flutter: 28 flutter:
25 sdk: flutter 29 sdk: flutter
26 # add flutter_screenutil 30 # add flutter_screenutil
27 - flutter_screenutil: ^2.3.0 31 + flutter_screenutil: ^3.0.0-beta.1
28 ``` 32 ```
29 33
30 ### Add the following imports to your Dart code: 34 ### Add the following imports to your Dart code:
@@ -36,26 +40,25 @@ import 'package:flutter_screenutil/flutter_screenutil.dart'; @@ -36,26 +40,25 @@ import 'package:flutter_screenutil/flutter_screenutil.dart';
36 40
37 |Property|Type|Default Value|Description| 41 |Property|Type|Default Value|Description|
38 |:---|:---|:---|:---| 42 |:---|:---|:---|:---|
39 -|width|double|1080px|The width of the device in the design draft, in px|  
40 -|height|double|1920px|The height of the device in the design draft, in px| 43 +|designSize|Size|Size(1080, 1920)|The size of the device in the design draft, in px|
41 |allowFontScaling|bool|false|Sets whether the font size is scaled according to the system's "font size" assist option| 44 |allowFontScaling|bool|false|Sets whether the font size is scaled according to the system's "font size" assist option|
42 45
43 ### Initialize and set the fit size and font size to scale according to the system's "font size" accessibility option 46 ### Initialize and set the fit size and font size to scale according to the system's "font size" accessibility option
44 -Please set the width and height of the design draft before use, the width and height of the design draft (unit px).  
45 -Be sure to set the page in the MaterialApp's home/initialRoute(ie the entry file, just set it once) to ensure that the fit size is set before each use: 47 +Please set the size of the design draft before use, the width and height of the design draft (unit px).
  48 +
46 49
47 ```dart 50 ```dart
48 51
49 //fill in the screen size of the device in the design 52 //fill in the screen size of the device in the design
50 53
51 //default value : width : 1080px , height:1920px , allowFontScaling:false 54 //default value : width : 1080px , height:1920px , allowFontScaling:false
52 -ScreenUtil.init(context); 55 +ScreenUtil.init();
53 56
54 //If the design is based on the size of the iPhone6 ​​(iPhone6 ​​750*1334) 57 //If the design is based on the size of the iPhone6 ​​(iPhone6 ​​750*1334)
55 -ScreenUtil.init(context, width: 750, height: 1334); 58 +ScreenUtil.init(designSize: Size(750, 1334));
56 59
57 //If you want to set the font size is scaled according to the system's "font size" assist option 60 //If you want to set the font size is scaled according to the system's "font size" assist option
58 -ScreenUtil.init(context, width: 750, height: 1334, allowFontScaling: true); 61 +ScreenUtil.init(designSize: Size(750, 1334), allowFontScaling: true);
59 62
60 ``` 63 ```
61 64
@@ -72,12 +75,12 @@ ScreenUtil.init(context, width: 750, height: 1334, allowFontScaling: true); @@ -72,12 +75,12 @@ ScreenUtil.init(context, width: 750, height: 1334, allowFontScaling: true);
72 ScreenUtil().setSp(24, allowFontScalingSelf: true) (sdk>=2.6 : 24.ssp) //Adapter font(fonts will scale to respect Text Size accessibility settings) 75 ScreenUtil().setSp(24, allowFontScalingSelf: true) (sdk>=2.6 : 24.ssp) //Adapter font(fonts will scale to respect Text Size accessibility settings)
73 ScreenUtil().setSp(24, allowFontScalingSelf: false) (sdk>=2.6 : 24.nsp) //Adapter font(fonts will not scale to respect Text Size accessibility settings) 76 ScreenUtil().setSp(24, allowFontScalingSelf: false) (sdk>=2.6 : 24.nsp) //Adapter font(fonts will not scale to respect Text Size accessibility settings)
74 77
75 - ScreenUtil.pixelRatio //Device pixel density  
76 - ScreenUtil.screenWidth (sdk>=2.6 : 1.wp) //Device width  
77 - ScreenUtil.screenHeight (sdk>=2.6 : 1.hp) //Device height  
78 - ScreenUtil.bottomBarHeight //Bottom safe zone distance, suitable for buttons with full screen  
79 - ScreenUtil.statusBarHeight //Status bar height , Notch will be higher Unit px  
80 - ScreenUtil.textScaleFactor //System font scaling factor 78 + ScreenUtil().pixelRatio //Device pixel density
  79 + ScreenUtil().screenWidth (sdk>=2.6 : 1.wp) //Device width
  80 + ScreenUtil().screenHeight (sdk>=2.6 : 1.hp) //Device height
  81 + ScreenUtil().bottomBarHeight //Bottom safe zone distance, suitable for buttons with full screen
  82 + ScreenUtil().statusBarHeight //Status bar height , Notch will be higher Unit px
  83 + ScreenUtil().textScaleFactor //System font scaling factor
81 84
82 ScreenUtil().scaleWidth //Ratio of actual width dp to design draft px 85 ScreenUtil().scaleWidth //Ratio of actual width dp to design draft px
83 ScreenUtil().scaleHeight //Ratio of actual height dp to design draft px 86 ScreenUtil().scaleHeight //Ratio of actual height dp to design draft px
@@ -166,167 +169,11 @@ Column( @@ -166,167 +169,11 @@ Column(
166 ) 169 )
167 ``` 170 ```
168 171
169 -```dart  
170 -//import  
171 -import 'package:flutter/material.dart';  
172 -import 'package:flutter_screenutil/flutter_screenutil.dart';  
173 -  
174 -void main() => runApp(MyApp());  
175 -  
176 -class MyApp extends StatelessWidget {  
177 - @override  
178 - Widget build(BuildContext context) {  
179 - return MaterialApp(  
180 - debugShowCheckedModeBanner: false,  
181 - title: 'Flutter_ScreenUtil',  
182 - theme: ThemeData(  
183 - primarySwatch: Colors.blue,  
184 - ),  
185 - home: MyHomePage(),  
186 - );  
187 - }  
188 -}  
189 -  
190 -class MyHomePage extends StatefulWidget {  
191 - @override  
192 - _MyHomePageState createState() => _MyHomePageState();  
193 -}  
194 -  
195 -class _MyHomePageState extends State<MyHomePage> {  
196 - @override  
197 - Widget build(BuildContext context) {  
198 - //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)  
199 - ScreenUtil.init(width: 750, height: 1334, allowFontScaling: false);  
200 -  
201 - return ExampleWidget(title: 'FlutterScreenUtil Demo');  
202 - }  
203 -}  
204 -  
205 -class ExampleWidget extends StatefulWidget {  
206 - const ExampleWidget({Key key, this.title}) : super(key: key);  
207 -  
208 - final String title;  
209 -  
210 - @override  
211 - _ExampleWidgetState createState() => _ExampleWidgetState();  
212 -}  
213 -  
214 -class _ExampleWidgetState extends State<ExampleWidget> {  
215 - @override  
216 - Widget build(BuildContext context) {  
217 - printScreenInformation();  
218 - return Scaffold(  
219 - appBar: AppBar(  
220 - title: Text(widget.title),  
221 - ),  
222 - body: SingleChildScrollView(  
223 - child: Column(  
224 - crossAxisAlignment: CrossAxisAlignment.center,  
225 - children: <Widget>[  
226 - Row(  
227 - children: <Widget>[  
228 - Container(  
229 - padding: EdgeInsets.all(ScreenUtil().setWidth(10)),  
230 - width: ScreenUtil().setWidth(375),  
231 - height: ScreenUtil().setHeight(200),  
232 - color: Colors.red,  
233 - child: Text(  
234 - 'My width:${ScreenUtil().setWidth(375)}dp \n'  
235 - 'My height:${ScreenUtil().setHeight(200)}dp',  
236 - style: TextStyle(  
237 - color: Colors.white, fontSize: ScreenUtil().setSp(24)),  
238 - ),  
239 - ),  
240 - Container(  
241 - padding: EdgeInsets.all(ScreenUtil().setWidth(10)),  
242 - width: ScreenUtil().setWidth(375),  
243 - height: ScreenUtil().setHeight(200),  
244 - color: Colors.blue,  
245 - child: Text(  
246 - 'My width:${ScreenUtil().setWidth(375)}dp \n'  
247 - 'My height:${ScreenUtil().setHeight(200)}dp',  
248 - style: TextStyle(  
249 - color: Colors.white,  
250 - fontSize: ScreenUtil().setSp(24))),  
251 - ),  
252 - ],  
253 - ),  
254 - Text('Device width:${ScreenUtil.screenWidth}dp'),  
255 - Text('Device height:${ScreenUtil.screenHeight}dp'),  
256 - Text('Device width:${ScreenUtil.screenWidthPx}px'),  
257 - Text('Device height:${ScreenUtil.screenHeightPx}px'),  
258 - Text('Device pixel density:${ScreenUtil.pixelRatio}'),  
259 - Text('Bottom safe zone distance:${ScreenUtil.bottomBarHeight}dp'),  
260 - Text('Status bar height:${ScreenUtil.statusBarHeight}dp'),  
261 - Text(  
262 - 'Ratio of actual width dp to design draft px:${ScreenUtil().scaleWidth}',  
263 - textAlign: TextAlign.center,  
264 - ),  
265 - Text(  
266 - 'Ratio of actual height dp to design draft px:${ScreenUtil().scaleHeight}',  
267 - textAlign: TextAlign.center,  
268 - ),  
269 - SizedBox(  
270 - height: ScreenUtil().setHeight(100),  
271 - ),  
272 - Text('System font scaling factor:${ScreenUtil.textScaleFactor}'),  
273 - Column(  
274 - crossAxisAlignment: CrossAxisAlignment.start,  
275 - children: <Widget>[  
276 - Text(  
277 - 'My font size is 24px on the design draft and will not change with the system.',  
278 - style: TextStyle(  
279 - color: Colors.black,  
280 - fontSize: ScreenUtil().setSp(24),  
281 - )),  
282 - Text(  
283 - 'My font size is 24px on the design draft and will change with the system.',  
284 - style: TextStyle(  
285 - color: Colors.black,  
286 - fontSize: ScreenUtil()  
287 - .setSp(24, allowFontScalingSelf: true))),  
288 - ],  
289 - )  
290 - ],  
291 - ),  
292 - ),  
293 - floatingActionButton: FloatingActionButton(  
294 - child: Icon(Icons.title),  
295 - onPressed: () {  
296 - ScreenUtil.init(width: 1500, height: 1334, allowFontScaling: false);  
297 - setState(() {});  
298 - },  
299 - ),  
300 - );  
301 - }  
302 -  
303 - void printScreenInformation() {  
304 - print('Device width dp:${ScreenUtil.screenWidth}'); //Device width  
305 - print('Device height dp:${ScreenUtil.screenHeight}'); //Device height  
306 - print(  
307 - 'Device pixel density:${ScreenUtil.pixelRatio}'); //Device pixel density  
308 - print(  
309 - 'Bottom safe zone distance dp:${ScreenUtil.bottomBarHeight}'); //Bottom safe zone distance,suitable for buttons with full screen  
310 - print(  
311 - 'Status bar height dp:${ScreenUtil.statusBarHeight}dp'); //Status bar height , Notch will be higher Unit dp  
312 - print(  
313 - 'Ratio of actual width dp to design draft px:${ScreenUtil().scaleWidth}');  
314 - print(  
315 - 'Ratio of actual height dp to design draft px:${ScreenUtil().scaleHeight}');  
316 - print(  
317 - 'The ratio of font and width to the size of the design:${ScreenUtil().scaleWidth * ScreenUtil.pixelRatio}');  
318 - print(  
319 - 'The ratio of height width to the size of the design:${ScreenUtil().scaleHeight * ScreenUtil.pixelRatio}');  
320 - }  
321 -}  
322 -  
323 -```  
324 -  
325 -### example: 172 +### Example:
326 173
327 [example demo](/example/lib/main.dart) 174 [example demo](/example/lib/main.dart)
328 175
329 -effect: 176 +### Effect:
330 177
331 ![effect](demo_en.png) 178 ![effect](demo_en.png)
332 ![tablet effect](demo_tablet_en.png) 179 ![tablet effect](demo_tablet_en.png)
  1 +# 该分支适用于Flutter的Beta版
1 2
2 # flutter_ScreenUtil 3 # flutter_ScreenUtil
3 4
  1 +# This branch is suitable for the beta version of flutter
1 2
2 # flutter_screenutil 3 # flutter_screenutil
3 [![pub package](https://img.shields.io/pub/v/flutter_screenutil.svg)](https://pub.dartlang.org/packages/flutter_screenutil) 4 [![pub package](https://img.shields.io/pub/v/flutter_screenutil.svg)](https://pub.dartlang.org/packages/flutter_screenutil)
1 -# example  
2 -  
3 -flutter_screenutil example 1 +# Example
4 2
5 ![手机效果](../demo_zh.png) 3 ![手机效果](../demo_zh.png)
6 ![phone effect](../demo_en.png) 4 ![phone effect](../demo_en.png)
7 5
8 ![平板效果](../demo_tablet_zh.png) 6 ![平板效果](../demo_tablet_zh.png)
9 ![tablet effect](../demo_tablet_en.png) 7 ![tablet effect](../demo_tablet_en.png)
10 -## Getting Started 8 +
  9 +```dart
  10 +void main() {
  11 + WidgetsFlutterBinding.ensureInitialized();
  12 + //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)
  13 + ScreenUtil.init(designSize: Size(750, 1334), allowFontScaling: false);
  14 + runApp(MyApp());
  15 +}
  16 +
  17 +class MyApp extends StatelessWidget {
  18 + @override
  19 + Widget build(BuildContext context) {
  20 + return MaterialApp(
  21 + debugShowCheckedModeBanner: false,
  22 + title: 'Flutter_ScreenUtil',
  23 + theme: ThemeData(
  24 + primarySwatch: Colors.blue,
  25 + ),
  26 + home: ExampleWidget(title: 'FlutterScreenUtil Demo'),
  27 + );
  28 + }
  29 +}
  30 +
  31 +class ExampleWidget extends StatefulWidget {
  32 + const ExampleWidget({Key key, this.title}) : super(key: key);
  33 +
  34 + final String title;
  35 +
  36 + @override
  37 + _ExampleWidgetState createState() => _ExampleWidgetState();
  38 +}
  39 +
  40 +class _ExampleWidgetState extends State<ExampleWidget> {
  41 + @override
  42 + Widget build(BuildContext context) {
  43 + printScreenInformation();
  44 + return Scaffold(
  45 + appBar: AppBar(
  46 + title: Text(widget.title),
  47 + ),
  48 + body: SingleChildScrollView(
  49 + child: Column(
  50 + crossAxisAlignment: CrossAxisAlignment.center,
  51 + children: <Widget>[
  52 + Row(
  53 + children: <Widget>[
  54 + // Using Extensions
  55 + Container(
  56 + padding: EdgeInsets.all(10.w),
  57 + width: 0.5.wp,
  58 + height: 200.h,
  59 + color: Colors.red,
  60 + child: Text(
  61 + 'My width:${0.5.wp}dp \n'
  62 + 'My height:${200.h}dp',
  63 + style: TextStyle(
  64 + color: Colors.white,
  65 + fontSize: 24.sp,
  66 + ),
  67 + ),
  68 + ),
  69 + // Without using Extensions
  70 + Container(
  71 + padding: EdgeInsets.all(ScreenUtil().setWidth(10)),
  72 + width: ScreenUtil().screenWidth * 0.5,
  73 + height: ScreenUtil().setHeight(200),
  74 + color: Colors.blue,
  75 + child: Text(
  76 + 'My width:${ScreenUtil().screenWidth * 0.5}dp \n'
  77 + 'My height:${ScreenUtil().setHeight(200)}dp',
  78 + style: TextStyle(
  79 + color: Colors.white,
  80 + fontSize: ScreenUtil().setSp(24),
  81 + ),
  82 + ),
  83 + ),
  84 + ],
  85 + ),
  86 + Text('Device width:${ScreenUtil().screenWidthPx}px'),
  87 + Text('Device height:${ScreenUtil().screenHeightPx}px'),
  88 + Text('Device width:${ScreenUtil().screenWidth}dp'),
  89 + Text('Device height:${ScreenUtil().screenHeight}dp'),
  90 + Text('Device pixel density:${ScreenUtil().pixelRatio}'),
  91 + Text('Bottom safe zone distance:${ScreenUtil().bottomBarHeight}dp'),
  92 + Text('Status bar height:${ScreenUtil().statusBarHeight}dp'),
  93 + Text(
  94 + 'Ratio of actual width dp to design draft px:${ScreenUtil().scaleWidth}',
  95 + textAlign: TextAlign.center,
  96 + ),
  97 + Text(
  98 + 'Ratio of actual height dp to design draft px:${ScreenUtil().scaleHeight}',
  99 + textAlign: TextAlign.center,
  100 + ),
  101 + SizedBox(
  102 + height: ScreenUtil().setHeight(100),
  103 + ),
  104 + Text('System font scaling factor:${ScreenUtil().textScaleFactor}'),
  105 + Column(
  106 + crossAxisAlignment: CrossAxisAlignment.start,
  107 + children: <Widget>[
  108 + Text(
  109 + 'My font size is 24px on the design draft and will not change with the system.',
  110 + style: TextStyle(
  111 + color: Colors.black,
  112 + fontSize: 24.sp,
  113 + ),
  114 + ),
  115 + Text(
  116 + 'My font size is 24px on the design draft and will change with the system.',
  117 + style: ts.t1,
  118 + ),
  119 + ],
  120 + )
  121 + ],
  122 + ),
  123 + ),
  124 + floatingActionButton: FloatingActionButton(
  125 + child: Icon(Icons.title),
  126 + onPressed: () {
  127 + ScreenUtil.init(
  128 + designSize: Size(1500, 1334),
  129 + allowFontScaling: false,
  130 + );
  131 + setState(() {});
  132 + },
  133 + ),
  134 + );
  135 + }
  136 +
  137 + void printScreenInformation() {
  138 + print('Device width dp:${ScreenUtil().screenWidth}'); //Device width
  139 + print('Device height dp:${ScreenUtil().screenHeight}'); //Device height
  140 + print(
  141 + 'Device pixel density:${ScreenUtil().pixelRatio}'); //Device pixel density
  142 + print(
  143 + 'Bottom safe zone distance dp:${ScreenUtil().bottomBarHeight}'); //Bottom safe zone distance,suitable for buttons with full screen
  144 + print(
  145 + 'Status bar height px:${ScreenUtil().statusBarHeight}dp'); //Status bar height , Notch will be higher Unit px
  146 + print(
  147 + 'Ratio of actual width dp to design draft px:${ScreenUtil().scaleWidth}');
  148 + print(
  149 + 'Ratio of actual height dp to design draft px:${ScreenUtil().scaleHeight}');
  150 + print(
  151 + 'The ratio of font and width to the size of the design:${ScreenUtil().scaleWidth * ScreenUtil().pixelRatio}');
  152 + print(
  153 + 'The ratio of height width to the size of the design:${ScreenUtil().scaleHeight * ScreenUtil().pixelRatio}');
  154 + print('System font scaling:${ScreenUtil().textScaleFactor}');
  155 + print('0.5 times the screen width:${0.5.wp}');
  156 + print('0.5 times the screen height:${0.5.hp}');
  157 + }
  158 +}
  159 +```
11 160
1 -*.iml  
2 -*.class  
3 -.gradle 1 +gradle-wrapper.jar
  2 +/.gradle
  3 +/captures/
  4 +/gradlew
  5 +/gradlew.bat
4 /local.properties 6 /local.properties
5 -/.idea/workspace.xml  
6 -/.idea/libraries  
7 -.DS_Store  
8 -/build  
9 -/captures  
10 GeneratedPluginRegistrant.java 7 GeneratedPluginRegistrant.java
1 -<?xml version="1.0" encoding="UTF-8"?>  
2 -<projectDescription>  
3 - <name>android</name>  
4 - <comment>Project android created by Buildship.</comment>  
5 - <projects>  
6 - </projects>  
7 - <buildSpec>  
8 - <buildCommand>  
9 - <name>org.eclipse.buildship.core.gradleprojectbuilder</name>  
10 - <arguments>  
11 - </arguments>  
12 - </buildCommand>  
13 - </buildSpec>  
14 - <natures>  
15 - <nature>org.eclipse.buildship.core.gradleprojectnature</nature>  
16 - </natures>  
17 -</projectDescription>  
1 -<?xml version="1.0" encoding="UTF-8"?>  
2 -<classpath>  
3 - <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8/"/>  
4 - <classpathentry kind="con" path="org.eclipse.buildship.core.gradleclasspathcontainer"/>  
5 - <classpathentry kind="output" path="bin/default"/>  
6 -</classpath>  
1 -<?xml version="1.0" encoding="UTF-8"?>  
2 -<projectDescription>  
3 - <name>app</name>  
4 - <comment>Project app created by Buildship.</comment>  
5 - <projects>  
6 - </projects>  
7 - <buildSpec>  
8 - <buildCommand>  
9 - <name>org.eclipse.jdt.core.javabuilder</name>  
10 - <arguments>  
11 - </arguments>  
12 - </buildCommand>  
13 - <buildCommand>  
14 - <name>org.eclipse.buildship.core.gradleprojectbuilder</name>  
15 - <arguments>  
16 - </arguments>  
17 - </buildCommand>  
18 - </buildSpec>  
19 - <natures>  
20 - <nature>org.eclipse.jdt.core.javanature</nature>  
21 - <nature>org.eclipse.buildship.core.gradleprojectnature</nature>  
22 - </natures>  
23 -</projectDescription>  
@@ -22,11 +22,16 @@ if (flutterVersionName == null) { @@ -22,11 +22,16 @@ if (flutterVersionName == null) {
22 } 22 }
23 23
24 apply plugin: 'com.android.application' 24 apply plugin: 'com.android.application'
  25 +apply plugin: 'kotlin-android'
25 apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" 26 apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
26 27
27 android { 28 android {
28 compileSdkVersion 28 29 compileSdkVersion 28
29 30
  31 + sourceSets {
  32 + main.java.srcDirs += 'src/main/kotlin'
  33 + }
  34 +
30 lintOptions { 35 lintOptions {
31 disable 'InvalidPackage' 36 disable 'InvalidPackage'
32 } 37 }
@@ -38,7 +43,6 @@ android { @@ -38,7 +43,6 @@ android {
38 targetSdkVersion 28 43 targetSdkVersion 28
39 versionCode flutterVersionCode.toInteger() 44 versionCode flutterVersionCode.toInteger()
40 versionName flutterVersionName 45 versionName flutterVersionName
41 - testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"  
42 } 46 }
43 47
44 buildTypes { 48 buildTypes {
@@ -55,7 +59,5 @@ flutter { @@ -55,7 +59,5 @@ flutter {
55 } 59 }
56 60
57 dependencies { 61 dependencies {
58 - testImplementation 'junit:junit:4.12'  
59 - androidTestImplementation 'com.android.support.test:runner:1.0.2'  
60 - androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' 62 + implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
61 } 63 }
  1 +<manifest xmlns:android="http://schemas.android.com/apk/res/android"
  2 + package="li.zhuoyuan.example">
  3 + <!-- Flutter needs it to communicate with the running application
  4 + to allow setting breakpoints, to provide hot reload, etc.
  5 + -->
  6 + <uses-permission android:name="android.permission.INTERNET"/>
  7 +</manifest>
1 <manifest xmlns:android="http://schemas.android.com/apk/res/android" 1 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
2 package="li.zhuoyuan.example"> 2 package="li.zhuoyuan.example">
3 -  
4 - <!-- The INTERNET permission is required for development. Specifically,  
5 - flutter needs it to communicate with the running application  
6 - to allow setting breakpoints, to provide hot reload, etc.  
7 - -->  
8 - <uses-permission android:name="android.permission.INTERNET"/>  
9 -  
10 <!-- io.flutter.app.FlutterApplication is an android.app.Application that 3 <!-- io.flutter.app.FlutterApplication is an android.app.Application that
11 calls FlutterMain.startInitialization(this); in its onCreate method. 4 calls FlutterMain.startInitialization(this); in its onCreate method.
12 In most cases you can leave this as-is, but you if you want to provide 5 In most cases you can leave this as-is, but you if you want to provide
@@ -20,20 +13,35 @@ @@ -20,20 +13,35 @@
20 android:name=".MainActivity" 13 android:name=".MainActivity"
21 android:launchMode="singleTop" 14 android:launchMode="singleTop"
22 android:theme="@style/LaunchTheme" 15 android:theme="@style/LaunchTheme"
23 - android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density" 16 + android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
24 android:hardwareAccelerated="true" 17 android:hardwareAccelerated="true"
25 android:windowSoftInputMode="adjustResize"> 18 android:windowSoftInputMode="adjustResize">
26 - <!-- This keeps the window background of the activity showing  
27 - until Flutter renders its first frame. It can be removed if  
28 - there is no splash screen (such as the default splash screen  
29 - defined in @style/LaunchTheme). --> 19 + <!-- Specifies an Android theme to apply to this Activity as soon as
  20 + the Android process has started. This theme is visible to the user
  21 + while the Flutter UI initializes. After that, this theme continues
  22 + to determine the Window background behind the Flutter UI. -->
30 <meta-data 23 <meta-data
31 - android:name="io.flutter.app.android.SplashScreenUntilFirstFrame"  
32 - android:value="true" /> 24 + android:name="io.flutter.embedding.android.NormalTheme"
  25 + android:resource="@style/NormalTheme"
  26 + />
  27 + <!-- Displays an Android View that continues showing the launch screen
  28 + Drawable until Flutter paints its first frame, then this splash
  29 + screen fades out. A splash screen is useful to avoid any visual
  30 + gap between the end of Android's launch screen and the painting of
  31 + Flutter's first frame. -->
  32 + <meta-data
  33 + android:name="io.flutter.embedding.android.SplashScreenDrawable"
  34 + android:resource="@drawable/launch_background"
  35 + />
33 <intent-filter> 36 <intent-filter>
34 <action android:name="android.intent.action.MAIN"/> 37 <action android:name="android.intent.action.MAIN"/>
35 <category android:name="android.intent.category.LAUNCHER"/> 38 <category android:name="android.intent.category.LAUNCHER"/>
36 </intent-filter> 39 </intent-filter>
37 </activity> 40 </activity>
  41 + <!-- Don't delete the meta-data below.
  42 + This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
  43 + <meta-data
  44 + android:name="flutterEmbedding"
  45 + android:value="2" />
38 </application> 46 </application>
39 </manifest> 47 </manifest>
1 -package li.zhuoyuan.example;  
2 -  
3 -import android.os.Bundle;  
4 -import io.flutter.app.FlutterActivity;  
5 -import io.flutter.plugins.GeneratedPluginRegistrant;  
6 -  
7 -public class MainActivity extends FlutterActivity {  
8 - @Override  
9 - protected void onCreate(Bundle savedInstanceState) {  
10 - super.onCreate(savedInstanceState);  
11 - GeneratedPluginRegistrant.registerWith(this);  
12 - }  
13 -}  
  1 +package li.zhuoyuan.example
  2 +
  3 +import io.flutter.embedding.android.FlutterActivity
  4 +
  5 +class MainActivity: FlutterActivity() {
  6 +}
1 <?xml version="1.0" encoding="utf-8"?> 1 <?xml version="1.0" encoding="utf-8"?>
2 <resources> 2 <resources>
  3 + <!-- Theme applied to the Android Window while the process is starting -->
3 <style name="LaunchTheme" parent="@android:style/Theme.Black.NoTitleBar"> 4 <style name="LaunchTheme" parent="@android:style/Theme.Black.NoTitleBar">
4 <!-- Show a splash screen on the activity. Automatically removed when 5 <!-- Show a splash screen on the activity. Automatically removed when
5 Flutter draws its first frame --> 6 Flutter draws its first frame -->
6 <item name="android:windowBackground">@drawable/launch_background</item> 7 <item name="android:windowBackground">@drawable/launch_background</item>
7 </style> 8 </style>
  9 + <!-- Theme applied to the Android Window as soon as the process has started.
  10 + This theme determines the color of the Android Window while your
  11 + Flutter UI initializes, as well as behind your Flutter UI while its
  12 + running.
  13 +
  14 + This Theme is only used starting with V2 of Flutter's Android embedding. -->
  15 + <style name="NormalTheme" parent="@android:style/Theme.Black.NoTitleBar">
  16 + <item name="android:windowBackground">@android:color/white</item>
  17 + </style>
8 </resources> 18 </resources>
  1 +<manifest xmlns:android="http://schemas.android.com/apk/res/android"
  2 + package="li.zhuoyuan.example">
  3 + <!-- Flutter needs it to communicate with the running application
  4 + to allow setting breakpoints, to provide hot reload, etc.
  5 + -->
  6 + <uses-permission android:name="android.permission.INTERNET"/>
  7 +</manifest>
1 buildscript { 1 buildscript {
  2 + ext.kotlin_version = '1.3.50'
2 repositories { 3 repositories {
3 google() 4 google()
4 jcenter() 5 jcenter()
5 - maven { url "http://download.flutter.io" }  
6 } 6 }
7 7
8 dependencies { 8 dependencies {
9 - classpath 'com.android.tools.build:gradle:3.1.2' 9 + classpath 'com.android.tools.build:gradle:3.5.0'
  10 + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
10 } 11 }
11 } 12 }
12 13
@@ -14,7 +15,6 @@ allprojects { @@ -14,7 +15,6 @@ allprojects {
14 repositories { 15 repositories {
15 google() 16 google()
16 jcenter() 17 jcenter()
17 - maven { url "http://download.flutter.io" }  
18 } 18 }
19 } 19 }
20 20
1 org.gradle.jvmargs=-Xmx1536M 1 org.gradle.jvmargs=-Xmx1536M
2 android.enableR8=true 2 android.enableR8=true
3 android.useAndroidX=true 3 android.useAndroidX=true
4 -android.enableJetifier=true  
  4 +android.enableJetifier=true
@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
3 distributionPath=wrapper/dists 3 distributionPath=wrapper/dists
4 zipStoreBase=GRADLE_USER_HOME 4 zipStoreBase=GRADLE_USER_HOME
5 zipStorePath=wrapper/dists 5 zipStorePath=wrapper/dists
6 -distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip 6 +distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-all.zip
1 -#!/usr/bin/env bash  
2 -  
3 -##############################################################################  
4 -##  
5 -## Gradle start up script for UN*X  
6 -##  
7 -##############################################################################  
8 -  
9 -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.  
10 -DEFAULT_JVM_OPTS=""  
11 -  
12 -APP_NAME="Gradle"  
13 -APP_BASE_NAME=`basename "$0"`  
14 -  
15 -# Use the maximum available, or set MAX_FD != -1 to use that value.  
16 -MAX_FD="maximum"  
17 -  
18 -warn ( ) {  
19 - echo "$*"  
20 -}  
21 -  
22 -die ( ) {  
23 - echo  
24 - echo "$*"  
25 - echo  
26 - exit 1  
27 -}  
28 -  
29 -# OS specific support (must be 'true' or 'false').  
30 -cygwin=false  
31 -msys=false  
32 -darwin=false  
33 -case "`uname`" in  
34 - CYGWIN* )  
35 - cygwin=true  
36 - ;;  
37 - Darwin* )  
38 - darwin=true  
39 - ;;  
40 - MINGW* )  
41 - msys=true  
42 - ;;  
43 -esac  
44 -  
45 -# Attempt to set APP_HOME  
46 -# Resolve links: $0 may be a link  
47 -PRG="$0"  
48 -# Need this for relative symlinks.  
49 -while [ -h "$PRG" ] ; do  
50 - ls=`ls -ld "$PRG"`  
51 - link=`expr "$ls" : '.*-> \(.*\)$'`  
52 - if expr "$link" : '/.*' > /dev/null; then  
53 - PRG="$link"  
54 - else  
55 - PRG=`dirname "$PRG"`"/$link"  
56 - fi  
57 -done  
58 -SAVED="`pwd`"  
59 -cd "`dirname \"$PRG\"`/" >/dev/null  
60 -APP_HOME="`pwd -P`"  
61 -cd "$SAVED" >/dev/null  
62 -  
63 -CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar  
64 -  
65 -# Determine the Java command to use to start the JVM.  
66 -if [ -n "$JAVA_HOME" ] ; then  
67 - if [ -x "$JAVA_HOME/jre/sh/java" ] ; then  
68 - # IBM's JDK on AIX uses strange locations for the executables  
69 - JAVACMD="$JAVA_HOME/jre/sh/java"  
70 - else  
71 - JAVACMD="$JAVA_HOME/bin/java"  
72 - fi  
73 - if [ ! -x "$JAVACMD" ] ; then  
74 - die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME  
75 -  
76 -Please set the JAVA_HOME variable in your environment to match the  
77 -location of your Java installation."  
78 - fi  
79 -else  
80 - JAVACMD="java"  
81 - which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.  
82 -  
83 -Please set the JAVA_HOME variable in your environment to match the  
84 -location of your Java installation."  
85 -fi  
86 -  
87 -# Increase the maximum file descriptors if we can.  
88 -if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then  
89 - MAX_FD_LIMIT=`ulimit -H -n`  
90 - if [ $? -eq 0 ] ; then  
91 - if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then  
92 - MAX_FD="$MAX_FD_LIMIT"  
93 - fi  
94 - ulimit -n $MAX_FD  
95 - if [ $? -ne 0 ] ; then  
96 - warn "Could not set maximum file descriptor limit: $MAX_FD"  
97 - fi  
98 - else  
99 - warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"  
100 - fi  
101 -fi  
102 -  
103 -# For Darwin, add options to specify how the application appears in the dock  
104 -if $darwin; then  
105 - GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""  
106 -fi  
107 -  
108 -# For Cygwin, switch paths to Windows format before running java  
109 -if $cygwin ; then  
110 - APP_HOME=`cygpath --path --mixed "$APP_HOME"`  
111 - CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`  
112 - JAVACMD=`cygpath --unix "$JAVACMD"`  
113 -  
114 - # We build the pattern for arguments to be converted via cygpath  
115 - ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`  
116 - SEP=""  
117 - for dir in $ROOTDIRSRAW ; do  
118 - ROOTDIRS="$ROOTDIRS$SEP$dir"  
119 - SEP="|"  
120 - done  
121 - OURCYGPATTERN="(^($ROOTDIRS))"  
122 - # Add a user-defined pattern to the cygpath arguments  
123 - if [ "$GRADLE_CYGPATTERN" != "" ] ; then  
124 - OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"  
125 - fi  
126 - # Now convert the arguments - kludge to limit ourselves to /bin/sh  
127 - i=0  
128 - for arg in "$@" ; do  
129 - CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`  
130 - CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option  
131 -  
132 - if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition  
133 - eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`  
134 - else  
135 - eval `echo args$i`="\"$arg\""  
136 - fi  
137 - i=$((i+1))  
138 - done  
139 - case $i in  
140 - (0) set -- ;;  
141 - (1) set -- "$args0" ;;  
142 - (2) set -- "$args0" "$args1" ;;  
143 - (3) set -- "$args0" "$args1" "$args2" ;;  
144 - (4) set -- "$args0" "$args1" "$args2" "$args3" ;;  
145 - (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;  
146 - (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;  
147 - (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;  
148 - (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;  
149 - (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;  
150 - esac  
151 -fi  
152 -  
153 -# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules  
154 -function splitJvmOpts() {  
155 - JVM_OPTS=("$@")  
156 -}  
157 -eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS  
158 -JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"  
159 -  
160 -exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"  
1 -@if "%DEBUG%" == "" @echo off  
2 -@rem ##########################################################################  
3 -@rem  
4 -@rem Gradle startup script for Windows  
5 -@rem  
6 -@rem ##########################################################################  
7 -  
8 -@rem Set local scope for the variables with windows NT shell  
9 -if "%OS%"=="Windows_NT" setlocal  
10 -  
11 -@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.  
12 -set DEFAULT_JVM_OPTS=  
13 -  
14 -set DIRNAME=%~dp0  
15 -if "%DIRNAME%" == "" set DIRNAME=.  
16 -set APP_BASE_NAME=%~n0  
17 -set APP_HOME=%DIRNAME%  
18 -  
19 -@rem Find java.exe  
20 -if defined JAVA_HOME goto findJavaFromJavaHome  
21 -  
22 -set JAVA_EXE=java.exe  
23 -%JAVA_EXE% -version >NUL 2>&1  
24 -if "%ERRORLEVEL%" == "0" goto init  
25 -  
26 -echo.  
27 -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.  
28 -echo.  
29 -echo Please set the JAVA_HOME variable in your environment to match the  
30 -echo location of your Java installation.  
31 -  
32 -goto fail  
33 -  
34 -:findJavaFromJavaHome  
35 -set JAVA_HOME=%JAVA_HOME:"=%  
36 -set JAVA_EXE=%JAVA_HOME%/bin/java.exe  
37 -  
38 -if exist "%JAVA_EXE%" goto init  
39 -  
40 -echo.  
41 -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%  
42 -echo.  
43 -echo Please set the JAVA_HOME variable in your environment to match the  
44 -echo location of your Java installation.  
45 -  
46 -goto fail  
47 -  
48 -:init  
49 -@rem Get command-line arguments, handling Windowz variants  
50 -  
51 -if not "%OS%" == "Windows_NT" goto win9xME_args  
52 -if "%@eval[2+2]" == "4" goto 4NT_args  
53 -  
54 -:win9xME_args  
55 -@rem Slurp the command line arguments.  
56 -set CMD_LINE_ARGS=  
57 -set _SKIP=2  
58 -  
59 -:win9xME_args_slurp  
60 -if "x%~1" == "x" goto execute  
61 -  
62 -set CMD_LINE_ARGS=%*  
63 -goto execute  
64 -  
65 -:4NT_args  
66 -@rem Get arguments from the 4NT Shell from JP Software  
67 -set CMD_LINE_ARGS=%$  
68 -  
69 -:execute  
70 -@rem Setup the command line  
71 -  
72 -set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar  
73 -  
74 -@rem Execute Gradle  
75 -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%  
76 -  
77 -:end  
78 -@rem End local scope for the variables with windows NT shell  
79 -if "%ERRORLEVEL%"=="0" goto mainEnd  
80 -  
81 -:fail  
82 -rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of  
83 -rem the _cmd.exe /c_ return code!  
84 -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1  
85 -exit /b 1  
86 -  
87 -:mainEnd  
88 -if "%OS%"=="Windows_NT" endlocal  
89 -  
90 -:omega  
  1 +// Copyright 2014 The Flutter Authors. All rights reserved.
  2 +// Use of this source code is governed by a BSD-style license that can be
  3 +// found in the LICENSE file.
  4 +
1 include ':app' 5 include ':app'
2 6
3 -def flutterProjectRoot = rootProject.projectDir.parentFile.toPath() 7 +def localPropertiesFile = new File(rootProject.projectDir, "local.properties")
  8 +def properties = new Properties()
4 9
5 -def plugins = new Properties()  
6 -def pluginsFile = new File(flutterProjectRoot.toFile(), '.flutter-plugins')  
7 -if (pluginsFile.exists()) {  
8 - pluginsFile.withReader('UTF-8') { reader -> plugins.load(reader) }  
9 -} 10 +assert localPropertiesFile.exists()
  11 +localPropertiesFile.withReader("UTF-8") { reader -> properties.load(reader) }
10 12
11 -plugins.each { name, path ->  
12 - def pluginDirectory = flutterProjectRoot.resolve(path).resolve('android').toFile()  
13 - include ":$name"  
14 - project(":$name").projectDir = pluginDirectory  
15 -} 13 +def flutterSdkPath = properties.getProperty("flutter.sdk")
  14 +assert flutterSdkPath != null, "flutter.sdk not set in local.properties"
  15 +apply from: "$flutterSdkPath/packages/flutter_tools/gradle/app_plugin_loader.gradle"
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=/Users/lizhuoyuan/Development/flutter"  
4 -export "FLUTTER_APPLICATION_PATH=/Users/lizhuoyuan/Development/Project/flutter_screenutil/example"  
5 -export "FLUTTER_TARGET=lib/main.dart" 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"
6 export "FLUTTER_BUILD_DIR=build" 6 export "FLUTTER_BUILD_DIR=build"
7 -export "SYMROOT=${SOURCE_ROOT}/../build/ios"  
8 -export "FLUTTER_FRAMEWORK_DIR=/Users/lizhuoyuan/Development/flutter/bin/cache/artifacts/engine/ios" 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"
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"
1 import 'dart:ui'; 1 import 'dart:ui';
2 2
3 -import 'package:example/text_style.dart';  
4 import 'package:flutter/material.dart'; 3 import 'package:flutter/material.dart';
5 import 'package:flutter_screenutil/flutter_screenutil.dart'; 4 import 'package:flutter_screenutil/flutter_screenutil.dart';
6 5
7 -void main() => runApp(MyApp()); 6 +import 'text_style.dart';
  7 +
  8 +void main() {
  9 + WidgetsFlutterBinding.ensureInitialized();
  10 + //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)
  11 + ScreenUtil.init(designSize: Size(750, 1334), allowFontScaling: false);
  12 + runApp(MyApp());
  13 +}
8 14
9 class MyApp extends StatelessWidget { 15 class MyApp extends StatelessWidget {
10 @override 16 @override
@@ -15,20 +21,11 @@ class MyApp extends StatelessWidget { @@ -15,20 +21,11 @@ class MyApp extends StatelessWidget {
15 theme: ThemeData( 21 theme: ThemeData(
16 primarySwatch: Colors.blue, 22 primarySwatch: Colors.blue,
17 ), 23 ),
18 - home: MyHomePage(), 24 + home: ExampleWidget(title: 'FlutterScreenUtil Demo'),
19 ); 25 );
20 } 26 }
21 } 27 }
22 28
23 -class MyHomePage extends StatelessWidget {  
24 - @override  
25 - Widget build(BuildContext context) {  
26 - //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)  
27 - ScreenUtil.init(context, width: 750, height: 1334, allowFontScaling: false);  
28 - return ExampleWidget(title: 'FlutterScreenUtil Demo');  
29 - }  
30 -}  
31 -  
32 class ExampleWidget extends StatefulWidget { 29 class ExampleWidget extends StatefulWidget {
33 const ExampleWidget({Key key, this.title}) : super(key: key); 30 const ExampleWidget({Key key, this.title}) : super(key: key);
34 31
@@ -41,7 +38,7 @@ class ExampleWidget extends StatefulWidget { @@ -41,7 +38,7 @@ class ExampleWidget extends StatefulWidget {
41 class _ExampleWidgetState extends State<ExampleWidget> { 38 class _ExampleWidgetState extends State<ExampleWidget> {
42 @override 39 @override
43 Widget build(BuildContext context) { 40 Widget build(BuildContext context) {
44 - printScreenInformation(); 41 + // printScreenInformation();
45 return Scaffold( 42 return Scaffold(
46 appBar: AppBar( 43 appBar: AppBar(
47 title: Text(widget.title), 44 title: Text(widget.title),
@@ -52,39 +49,45 @@ class _ExampleWidgetState extends State<ExampleWidget> { @@ -52,39 +49,45 @@ class _ExampleWidgetState extends State<ExampleWidget> {
52 children: <Widget>[ 49 children: <Widget>[
53 Row( 50 Row(
54 children: <Widget>[ 51 children: <Widget>[
  52 + // Using Extensions
55 Container( 53 Container(
56 - padding: EdgeInsets.all(ScreenUtil().setWidth(10)),  
57 - width: 375.w, 54 + padding: EdgeInsets.all(10.w),
  55 + width: 0.5.wp,
58 height: 200.h, 56 height: 200.h,
59 color: Colors.red, 57 color: Colors.red,
60 child: Text( 58 child: Text(
61 - 'My width:${375.w}dp \n' 59 + 'My width:${0.5.wp}dp \n'
62 'My height:${200.h}dp', 60 'My height:${200.h}dp',
63 style: TextStyle( 61 style: TextStyle(
64 - color: Colors.white, fontSize: ScreenUtil().setSp(24)), 62 + color: Colors.white,
  63 + fontSize: 24.sp,
  64 + ),
65 ), 65 ),
66 ), 66 ),
  67 + // Without using Extensions
67 Container( 68 Container(
68 padding: EdgeInsets.all(ScreenUtil().setWidth(10)), 69 padding: EdgeInsets.all(ScreenUtil().setWidth(10)),
69 - width: ScreenUtil().setWidth(375), 70 + width: ScreenUtil().screenWidth * 0.5,
70 height: ScreenUtil().setHeight(200), 71 height: ScreenUtil().setHeight(200),
71 color: Colors.blue, 72 color: Colors.blue,
72 child: Text( 73 child: Text(
73 - 'My width:${0.5.wp}dp \n'  
74 - 'My height:${ScreenUtil().setHeight(200)}dp',  
75 - style: TextStyle(  
76 - color: Colors.white,  
77 - fontSize: ScreenUtil().setSp(24))), 74 + 'My width:${ScreenUtil().screenWidth * 0.5}dp \n'
  75 + 'My height:${ScreenUtil().setHeight(200)}dp',
  76 + style: TextStyle(
  77 + color: Colors.white,
  78 + fontSize: ScreenUtil().setSp(24),
  79 + ),
  80 + ),
78 ), 81 ),
79 ], 82 ],
80 ), 83 ),
81 - Text('Device width:${ScreenUtil.screenWidthPx}px'),  
82 - Text('Device height:${ScreenUtil.screenHeightPx}px'),  
83 - Text('Device width:${ScreenUtil.screenWidth}dp'),  
84 - Text('Device height:${ScreenUtil.screenHeight}dp'),  
85 - Text('Device pixel density:${ScreenUtil.pixelRatio}'),  
86 - Text('Bottom safe zone distance:${ScreenUtil.bottomBarHeight}dp'),  
87 - Text('Status bar height:${ScreenUtil.statusBarHeight}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}'),
  89 + Text('Bottom safe zone distance:${ScreenUtil().bottomBarHeight}dp'),
  90 + Text('Status bar height:${ScreenUtil().statusBarHeight}dp'),
88 Text( 91 Text(
89 'Ratio of actual width dp to design draft px:${ScreenUtil().scaleWidth}', 92 'Ratio of actual width dp to design draft px:${ScreenUtil().scaleWidth}',
90 textAlign: TextAlign.center, 93 textAlign: TextAlign.center,
@@ -96,19 +99,21 @@ class _ExampleWidgetState extends State<ExampleWidget> { @@ -96,19 +99,21 @@ class _ExampleWidgetState extends State<ExampleWidget> {
96 SizedBox( 99 SizedBox(
97 height: ScreenUtil().setHeight(100), 100 height: ScreenUtil().setHeight(100),
98 ), 101 ),
99 - Text('System font scaling factor:${ScreenUtil.textScaleFactor}'), 102 + Text('System font scaling factor:${ScreenUtil().textScaleFactor}'),
100 Column( 103 Column(
101 crossAxisAlignment: CrossAxisAlignment.start, 104 crossAxisAlignment: CrossAxisAlignment.start,
102 children: <Widget>[ 105 children: <Widget>[
103 Text( 106 Text(
104 - 'My font size is 24px on the design draft and will not change with the system.',  
105 - style: TextStyle(  
106 - color: Colors.black,  
107 - fontSize: 24.sp,  
108 - )), 107 + 'My font size is 24px on the design draft and will not change with the system.',
  108 + style: TextStyle(
  109 + color: Colors.black,
  110 + fontSize: 24.sp,
  111 + ),
  112 + ),
109 Text( 113 Text(
110 - 'My font size is 24px on the design draft and will change with the system.',  
111 - style: ts.t1), 114 + 'My font size is 24px on the design draft and will change with the system.',
  115 + style: ts.t1,
  116 + ),
112 ], 117 ],
113 ) 118 )
114 ], 119 ],
@@ -117,8 +122,10 @@ class _ExampleWidgetState extends State<ExampleWidget> { @@ -117,8 +122,10 @@ class _ExampleWidgetState extends State<ExampleWidget> {
117 floatingActionButton: FloatingActionButton( 122 floatingActionButton: FloatingActionButton(
118 child: Icon(Icons.title), 123 child: Icon(Icons.title),
119 onPressed: () { 124 onPressed: () {
120 - ScreenUtil.init(context,  
121 - width: 1500, height: 1334, allowFontScaling: false); 125 + ScreenUtil.init(
  126 + designSize: Size(1500, 1334),
  127 + allowFontScaling: false,
  128 + );
122 setState(() {}); 129 setState(() {});
123 }, 130 },
124 ), 131 ),
@@ -126,23 +133,23 @@ class _ExampleWidgetState extends State<ExampleWidget> { @@ -126,23 +133,23 @@ class _ExampleWidgetState extends State<ExampleWidget> {
126 } 133 }
127 134
128 void printScreenInformation() { 135 void printScreenInformation() {
129 - print('Device width dp:${ScreenUtil.screenWidth}'); //Device width  
130 - print('Device height dp:${ScreenUtil.screenHeight}'); //Device height 136 + print('Device width dp:${ScreenUtil().screenWidth}'); //Device width
  137 + print('Device height dp:${ScreenUtil().screenHeight}'); //Device height
131 print( 138 print(
132 - 'Device pixel density:${ScreenUtil.pixelRatio}'); //Device pixel density 139 + 'Device pixel density:${ScreenUtil().pixelRatio}'); //Device pixel density
133 print( 140 print(
134 - 'Bottom safe zone distance dp:${ScreenUtil.bottomBarHeight}'); //Bottom safe zone distance,suitable for buttons with full screen 141 + 'Bottom safe zone distance dp:${ScreenUtil().bottomBarHeight}'); //Bottom safe zone distance,suitable for buttons with full screen
135 print( 142 print(
136 - 'Status bar height px:${ScreenUtil.statusBarHeight}dp'); //Status bar height , Notch will be higher Unit px 143 + 'Status bar height px:${ScreenUtil().statusBarHeight}dp'); //Status bar height , Notch will be higher Unit px
137 print( 144 print(
138 'Ratio of actual width dp to design draft px:${ScreenUtil().scaleWidth}'); 145 'Ratio of actual width dp to design draft px:${ScreenUtil().scaleWidth}');
139 print( 146 print(
140 'Ratio of actual height dp to design draft px:${ScreenUtil().scaleHeight}'); 147 'Ratio of actual height dp to design draft px:${ScreenUtil().scaleHeight}');
141 print( 148 print(
142 - 'The ratio of font and width to the size of the design:${ScreenUtil().scaleWidth * ScreenUtil.pixelRatio}'); 149 + 'The ratio of font and width to the size of the design:${ScreenUtil().scaleWidth * ScreenUtil().pixelRatio}');
143 print( 150 print(
144 - 'The ratio of height width to the size of the design:${ScreenUtil().scaleHeight * ScreenUtil.pixelRatio}');  
145 - print('System font scaling:${ScreenUtil.textScaleFactor}'); 151 + 'The ratio of height width to the size of the design:${ScreenUtil().scaleHeight * ScreenUtil().pixelRatio}');
  152 + print('System font scaling:${ScreenUtil().textScaleFactor}');
146 print('0.5 times the screen width:${0.5.wp}'); 153 print('0.5 times the screen width:${0.5.wp}');
147 print('0.5 times the screen height:${0.5.hp}'); 154 print('0.5 times the screen height:${0.5.hp}');
148 } 155 }
1 -import 'package:example/text_style.dart';  
2 import 'package:flutter/material.dart'; 1 import 'package:flutter/material.dart';
3 import 'package:flutter_screenutil/flutter_screenutil.dart'; 2 import 'package:flutter_screenutil/flutter_screenutil.dart';
4 3
5 -void main() => runApp(MyApp()); 4 +import 'text_style.dart';
  5 +
  6 +void main() {
  7 + WidgetsFlutterBinding.ensureInitialized();
  8 + //设置适配尺寸 (填入设计稿中设备的屏幕尺寸) 此处假如设计稿是按iPhone6的尺寸设计的(iPhone6 750*1334)
  9 + ScreenUtil.init(designSize: Size(750, 1334), allowFontScaling: false);
  10 + runApp(MyApp());
  11 +}
6 12
7 class MyApp extends StatelessWidget { 13 class MyApp extends StatelessWidget {
8 @override 14 @override
@@ -13,31 +19,11 @@ class MyApp extends StatelessWidget { @@ -13,31 +19,11 @@ class MyApp extends StatelessWidget {
13 theme: ThemeData( 19 theme: ThemeData(
14 primarySwatch: Colors.blue, 20 primarySwatch: Colors.blue,
15 ), 21 ),
16 - home: MyHomePage(), 22 + home: ExampleWidget(title: 'FlutterScreenUtil示例'),
17 ); 23 );
18 } 24 }
19 } 25 }
20 26
21 -class MyHomePage extends StatefulWidget {  
22 - MyHomePage({Key key, this.title}) : super(key: key);  
23 -  
24 - final String title;  
25 -  
26 - @override  
27 - _MyHomePageState createState() => _MyHomePageState();  
28 -}  
29 -  
30 -class _MyHomePageState extends State<MyHomePage> {  
31 - @override  
32 - Widget build(BuildContext context) {  
33 - //设置适配尺寸 (填入设计稿中设备的屏幕尺寸) 此处假如设计稿是按iPhone6的尺寸设计的(iPhone6 750*1334)  
34 -  
35 - ScreenUtil.init(context, width: 750, height: 1334, allowFontScaling: false);  
36 -  
37 - return ExampleWidget(title: 'FlutterScreenUtil示例');  
38 - }  
39 -}  
40 -  
41 class ExampleWidget extends StatefulWidget { 27 class ExampleWidget extends StatefulWidget {
42 const ExampleWidget({Key key, this.title}) : super(key: key); 28 const ExampleWidget({Key key, this.title}) : super(key: key);
43 29
@@ -87,13 +73,13 @@ class _ExampleWidgetState extends State<ExampleWidget> { @@ -87,13 +73,13 @@ class _ExampleWidgetState extends State<ExampleWidget> {
87 ), 73 ),
88 ], 74 ],
89 ), 75 ),
90 - Text('设备宽度:${ScreenUtil.screenWidthPx}px'),  
91 - Text('设备高度:${ScreenUtil.screenHeightPx}px'),  
92 - Text('设备宽度:${ScreenUtil.screenWidth}dp'),  
93 - Text('设备高度:${ScreenUtil.screenHeight}dp'),  
94 - Text('设备的像素密度:${ScreenUtil.pixelRatio}'),  
95 - Text('底部安全区距离:${ScreenUtil.bottomBarHeight}dp'),  
96 - Text('状态栏高度:${ScreenUtil.statusBarHeight}dp'), 76 + Text('设备宽度:${ScreenUtil().screenWidthPx}px'),
  77 + Text('设备高度:${ScreenUtil().screenHeightPx}px'),
  78 + Text('设备宽度:${ScreenUtil().screenWidth}dp'),
  79 + Text('设备高度:${ScreenUtil().screenHeight}dp'),
  80 + Text('设备的像素密度:${ScreenUtil().pixelRatio}'),
  81 + Text('底部安全区距离:${ScreenUtil().bottomBarHeight}dp'),
  82 + Text('状态栏高度:${ScreenUtil().statusBarHeight}dp'),
97 Text( 83 Text(
98 '实际宽度的dp与设计稿px的比例:${ScreenUtil().scaleWidth}', 84 '实际宽度的dp与设计稿px的比例:${ScreenUtil().scaleWidth}',
99 textAlign: TextAlign.center, 85 textAlign: TextAlign.center,
@@ -105,7 +91,7 @@ class _ExampleWidgetState extends State<ExampleWidget> { @@ -105,7 +91,7 @@ class _ExampleWidgetState extends State<ExampleWidget> {
105 SizedBox( 91 SizedBox(
106 height: 100.h, 92 height: 100.h,
107 ), 93 ),
108 - Text('系统的字体缩放比例:${ScreenUtil.textScaleFactor}'), 94 + Text('系统的字体缩放比例:${ScreenUtil().textScaleFactor}'),
109 Column( 95 Column(
110 crossAxisAlignment: CrossAxisAlignment.start, 96 crossAxisAlignment: CrossAxisAlignment.start,
111 children: <Widget>[ 97 children: <Widget>[
@@ -125,8 +111,10 @@ class _ExampleWidgetState extends State<ExampleWidget> { @@ -125,8 +111,10 @@ class _ExampleWidgetState extends State<ExampleWidget> {
125 floatingActionButton: FloatingActionButton( 111 floatingActionButton: FloatingActionButton(
126 child: Icon(Icons.title), 112 child: Icon(Icons.title),
127 onPressed: () { 113 onPressed: () {
128 - ScreenUtil.init(context,  
129 - width: 1500, height: 1334, allowFontScaling: false); 114 + ScreenUtil.init(
  115 + designSize: Size(1500, 1334),
  116 + allowFontScaling: false,
  117 + );
130 setState(() {}); 118 setState(() {});
131 }, 119 },
132 ), 120 ),
@@ -134,21 +122,26 @@ class _ExampleWidgetState extends State<ExampleWidget> { @@ -134,21 +122,26 @@ class _ExampleWidgetState extends State<ExampleWidget> {
134 } 122 }
135 123
136 void printScreenInformation() { 124 void printScreenInformation() {
137 - print('设备宽度:${ScreenUtil.screenWidth}'); //Device width  
138 - print('设备高度:${ScreenUtil.screenHeight}'); //Device height  
139 - print('设备的像素密度:${ScreenUtil.pixelRatio}'); //Device pixel density 125 + print('设备宽度:${ScreenUtil().screenWidth}'); //Device width
  126 + print('设备高度:${ScreenUtil().screenHeight}'); //Device height
  127 + print('设备的像素密度:${ScreenUtil().pixelRatio}'); //Device pixel density
140 print( 128 print(
141 - '底部安全区距离:${ScreenUtil.bottomBarHeight}dp'); //Bottom safe zone distance,suitable for buttons with full screen 129 + '底部安全区距离:${ScreenUtil().bottomBarHeight}dp',
  130 + ); //Bottom safe zone distance,suitable for buttons with full screen
142 print( 131 print(
143 - '状态栏高度:${ScreenUtil.statusBarHeight}dp'); //Status bar height , Notch will be higher Unit px 132 + '状态栏高度:${ScreenUtil().statusBarHeight}dp',
  133 + ); //Status bar height , Notch will be higher Unit px
144 134
145 print('实际宽度的dp与设计稿px的比例:${ScreenUtil().scaleWidth}'); 135 print('实际宽度的dp与设计稿px的比例:${ScreenUtil().scaleWidth}');
146 print('实际高度的dp与设计稿px的比例:${ScreenUtil().scaleHeight}'); 136 print('实际高度的dp与设计稿px的比例:${ScreenUtil().scaleHeight}');
147 137
148 print( 138 print(
149 - '宽度和字体相对于设计稿放大的比例:${ScreenUtil().scaleWidth * ScreenUtil.pixelRatio}');  
150 - print('高度相对于设计稿放大的比例:${ScreenUtil().scaleHeight * ScreenUtil.pixelRatio}');  
151 - print('系统的字体缩放比例:${ScreenUtil.textScaleFactor}'); 139 + '宽度和字体相对于设计稿放大的比例:${ScreenUtil().scaleWidth * ScreenUtil().pixelRatio}',
  140 + );
  141 + print(
  142 + '高度相对于设计稿放大的比例:${ScreenUtil().scaleHeight * ScreenUtil().pixelRatio}',
  143 + );
  144 + print('系统的字体缩放比例:${ScreenUtil().textScaleFactor}');
152 145
153 print('屏幕宽度的0.5:${0.5.wp}'); 146 print('屏幕宽度的0.5:${0.5.wp}');
154 print('屏幕高度的0.5:${0.5.hp}'); 147 print('屏幕高度的0.5:${0.5.hp}');
@@ -4,91 +4,96 @@ @@ -4,91 +4,96 @@
4 */ 4 */
5 5
6 import 'package:flutter/material.dart'; 6 import 'package:flutter/material.dart';
  7 +import 'package:flutter/scheduler.dart';
7 8
8 class ScreenUtil { 9 class ScreenUtil {
9 static ScreenUtil _instance; 10 static ScreenUtil _instance;
10 - static const int defaultWidth = 1080;  
11 - static const int defaultHeight = 1920; 11 + static const Size defaultSize = Size(1080, 1920);
12 12
13 /// UI设计中手机尺寸 , px 13 /// UI设计中手机尺寸 , px
14 /// Size of the phone in UI Design , px 14 /// Size of the phone in UI Design , px
15 - num uiWidthPx;  
16 - num uiHeightPx; 15 + Size uiSize = defaultSize;
17 16
18 /// 控制字体是否要根据系统的“字体大小”辅助选项来进行缩放。默认值为false。 17 /// 控制字体是否要根据系统的“字体大小”辅助选项来进行缩放。默认值为false。
19 /// allowFontScaling Specifies whether fonts should scale to respect Text Size accessibility settings. The default is false. 18 /// allowFontScaling Specifies whether fonts should scale to respect Text Size accessibility settings. The default is false.
20 - bool allowFontScaling;  
21 -  
22 - static double _screenWidth;  
23 - static double _screenHeight;  
24 - static double _pixelRatio;  
25 - static double _statusBarHeight;  
26 - static double _bottomBarHeight;  
27 - static double _textScaleFactor;  
28 -  
29 - ScreenUtil._(); 19 + bool allowFontScaling = false;
  20 +
  21 + double _pixelRatio;
  22 + double _screenWidth;
  23 + double _screenHeight;
  24 + double _statusBarHeight;
  25 + double _bottomBarHeight;
  26 + double _textScaleFactor;
  27 +
  28 + ScreenUtil._() {
  29 + final window = SchedulerBinding.instance?.window;
  30 + assert(
  31 + window != null,
  32 + '\nYou need to explicitly call the `WidgetsFlutterBinding.ensureInitialized()`, before initializing ScreenUtil.',
  33 + );
  34 + _pixelRatio = window.devicePixelRatio;
  35 + _screenWidth = window.physicalSize.width / _pixelRatio;
  36 + _screenHeight = window.physicalSize.height / _pixelRatio;
  37 + _statusBarHeight = window.padding.top;
  38 + _bottomBarHeight = window.padding.bottom;
  39 + _textScaleFactor = window.textScaleFactor;
  40 + }
30 41
31 factory ScreenUtil() { 42 factory ScreenUtil() {
  43 + assert(
  44 + _instance != null,
  45 + '\nEnsure to initialize ScreenUtil before accessing it.',
  46 + );
32 return _instance; 47 return _instance;
33 } 48 }
34 49
35 - static void init(BuildContext context,  
36 - {num width = defaultWidth,  
37 - num height = defaultHeight,  
38 - bool allowFontScaling = false}) {  
39 - if (_instance == null) {  
40 - _instance = ScreenUtil._();  
41 - }  
42 - _instance.uiWidthPx = width;  
43 - _instance.uiHeightPx = height;  
44 - _instance.allowFontScaling = allowFontScaling;  
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; 50 + static void init({
  51 + Size designSize = defaultSize,
  52 + bool allowFontScaling = false,
  53 + }) {
  54 + _instance ??= ScreenUtil._();
  55 + _instance
  56 + ..uiSize = designSize
  57 + ..allowFontScaling = allowFontScaling;
53 } 58 }
54 59
55 /// 每个逻辑像素的字体像素数,字体的缩放比例 60 /// 每个逻辑像素的字体像素数,字体的缩放比例
56 /// The number of font pixels for each logical pixel. 61 /// The number of font pixels for each logical pixel.
57 - static double get textScaleFactor => _textScaleFactor; 62 + double get textScaleFactor => _textScaleFactor;
58 63
59 /// 设备的像素密度 64 /// 设备的像素密度
60 /// The size of the media in logical pixels (e.g, the size of the screen). 65 /// The size of the media in logical pixels (e.g, the size of the screen).
61 - static double get pixelRatio => _pixelRatio; 66 + double get pixelRatio => _pixelRatio;
62 67
63 /// 当前设备宽度 dp 68 /// 当前设备宽度 dp
64 /// The horizontal extent of this size. 69 /// The horizontal extent of this size.
65 - static double get screenWidth => _screenWidth; 70 + double get screenWidth => _screenWidth;
66 71
67 ///当前设备高度 dp 72 ///当前设备高度 dp
68 ///The vertical extent of this size. dp 73 ///The vertical extent of this size. dp
69 - static double get screenHeight => _screenHeight; 74 + double get screenHeight => _screenHeight;
70 75
71 /// 当前设备宽度 px 76 /// 当前设备宽度 px
72 /// The vertical extent of this size. px 77 /// The vertical extent of this size. px
73 - static double get screenWidthPx => _screenWidth * _pixelRatio; 78 + double get screenWidthPx => _screenWidth * _pixelRatio;
74 79
75 /// 当前设备高度 px 80 /// 当前设备高度 px
76 /// The vertical extent of this size. px 81 /// The vertical extent of this size. px
77 - static double get screenHeightPx => _screenHeight * _pixelRatio; 82 + double get screenHeightPx => _screenHeight * _pixelRatio;
78 83
79 /// 状态栏高度 dp 刘海屏会更高 84 /// 状态栏高度 dp 刘海屏会更高
80 /// The offset from the top 85 /// The offset from the top
81 - static double get statusBarHeight => _statusBarHeight; 86 + double get statusBarHeight => _statusBarHeight;
82 87
83 /// 底部安全区距离 dp 88 /// 底部安全区距离 dp
84 /// The offset from the bottom. 89 /// The offset from the bottom.
85 - static double get bottomBarHeight => _bottomBarHeight; 90 + double get bottomBarHeight => _bottomBarHeight;
86 91
87 /// 实际的dp与UI设计px的比例 92 /// 实际的dp与UI设计px的比例
88 /// The ratio of the actual dp to the design draft px 93 /// The ratio of the actual dp to the design draft px
89 - double get scaleWidth => _screenWidth / uiWidthPx; 94 + double get scaleWidth => _screenWidth / uiSize.width;
90 95
91 - double get scaleHeight => _screenHeight / uiHeightPx; 96 + double get scaleHeight => _screenHeight / uiSize.height;
92 97
93 double get scaleText => scaleWidth; 98 double get scaleText => scaleWidth;
94 99
@@ -18,9 +18,9 @@ extension SizeExtension on num { @@ -18,9 +18,9 @@ extension SizeExtension on num {
18 18
19 ///屏幕宽度的倍数 19 ///屏幕宽度的倍数
20 ///Multiple of screen width 20 ///Multiple of screen width
21 - num get wp => ScreenUtil.screenWidth * this; 21 + num get wp => ScreenUtil().screenWidth * this;
22 22
23 ///屏幕高度的倍数 23 ///屏幕高度的倍数
24 ///Multiple of screen height 24 ///Multiple of screen height
25 - num get hp => ScreenUtil.screenHeight * this; 25 + num get hp => ScreenUtil().screenHeight * this;
26 } 26 }
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.3.1 3 +version: 3.0.0-beta.1
4 homepage: https://github.com/OpenFlutter/flutter_screenutil 4 homepage: https://github.com/OpenFlutter/flutter_screenutil
5 5
6 environment: 6 environment:
7 sdk: ">=2.6.0 <3.0.0" 7 sdk: ">=2.6.0 <3.0.0"
  8 + flutter: ">=1.19.0-4.3.pre"
8 9
9 dependencies: 10 dependencies:
10 flutter: 11 flutter:
@@ -13,38 +14,3 @@ dependencies: @@ -13,38 +14,3 @@ dependencies:
13 dev_dependencies: 14 dev_dependencies:
14 flutter_test: 15 flutter_test:
15 sdk: flutter 16 sdk: flutter
16 -  
17 -# For information on the generic Dart part of this file, see the  
18 -# following page: https://www.dartlang.org/tools/pub/pubspec  
19 -  
20 -# The following section is specific to Flutter.  
21 -flutter:  
22 - # To add assets to your package, add an assets section, like this:  
23 - # assets:  
24 - # - images/a_dot_burr.jpeg  
25 - # - images/a_dot_ham.jpeg  
26 - #  
27 - # For details regarding assets in packages, see  
28 - # https://flutter.io/assets-and-images/#from-packages  
29 - #  
30 - # An image asset can refer to one or more resolution-specific "variants", see  
31 - # https://flutter.io/assets-and-images/#resolution-aware.  
32 - # To add custom fonts to your package, add a fonts section here,  
33 - # in this "flutter" section. Each entry in this list should have a  
34 - # "family" key with the font family name, and a "fonts" key with a  
35 - # list giving the asset and other descriptors for the font. For  
36 - # example:  
37 - # fonts:  
38 - # - family: Schyler  
39 - # fonts:  
40 - # - asset: fonts/Schyler-Regular.ttf  
41 - # - asset: fonts/Schyler-Italic.ttf  
42 - # style: italic  
43 - # - family: Trajan Pro  
44 - # fonts:  
45 - # - asset: fonts/TrajanPro.ttf  
46 - # - asset: fonts/TrajanPro_Bold.ttf  
47 - # weight: 700  
48 - #  
49 - # For details regarding fonts in packages, see  
50 - # https://flutter.io/custom-fonts/#from-packages