LiZhuoyuan

Merge branch 'beta'

# Conflicts:
#	README_CN.md
#	README_PT.md
@@ -6,6 +6,15 @@ @@ -6,6 +6,15 @@
6 * @Description: Update log 6 * @Description: Update log
7 --> 7 -->
8 8
  9 +# 3.0.0-beta.2
  10 +- readme update
  11 +
  12 +# 3.0.0-beta.1
  13 +**BREAKING CHANGES**
  14 +- `BuildContext` is no more required while initializing. i.e. ScreenUtil.init(~~context~~)
  15 +- Initialize size of design draft using `designSize` instead of width & height.
  16 +- All the static methods are now member methods.
  17 +
9 # 2.3.1 18 # 2.3.1
10 - add textStyle Example. 19 - add textStyle Example.
11 20
1 -  
2 # flutter_screenutil 1 # flutter_screenutil
3 [![pub package](https://img.shields.io/pub/v/flutter_screenutil.svg)](https://pub.dev/packages/flutter_screenutil) 2 [![pub package](https://img.shields.io/pub/v/flutter_screenutil.svg)](https://pub.dev/packages/flutter_screenutil)
4 3
@@ -29,9 +28,8 @@ dependencies: @@ -29,9 +28,8 @@ dependencies:
29 flutter: 28 flutter:
30 sdk: flutter 29 sdk: flutter
31 # add flutter_screenutil 30 # add flutter_screenutil
32 - flutter_screenutil: ^2.3.0 31 + flutter_screenutil: ^3.0.0-beta.1
33 ``` 32 ```
34 -  
35 ### Add the following imports to your Dart code: 33 ### Add the following imports to your Dart code:
36 ``` 34 ```
37 import 'package:flutter_screenutil/flutter_screenutil.dart'; 35 import 'package:flutter_screenutil/flutter_screenutil.dart';
@@ -41,26 +39,31 @@ import 'package:flutter_screenutil/flutter_screenutil.dart'; @@ -41,26 +39,31 @@ import 'package:flutter_screenutil/flutter_screenutil.dart';
41 39
42 |Property|Type|Default Value|Description| 40 |Property|Type|Default Value|Description|
43 |:---|:---|:---|:---| 41 |:---|:---|:---|:---|
44 -|width|double|1080px|The width of the device in the design draft, in px|  
45 -|height|double|1920px|The height of the device in the design draft, in px| 42 +|designSize|Size|Size(1080, 1920)|The size of the device in the design draft, in px|
46 |allowFontScaling|bool|false|Sets whether the font size is scaled according to the system's "font size" assist option| 43 |allowFontScaling|bool|false|Sets whether the font size is scaled according to the system's "font size" assist option|
47 44
48 ### Initialize and set the fit size and font size to scale according to the system's "font size" accessibility option 45 ### Initialize and set the fit size and font size to scale according to the system's "font size" accessibility option
49 -Please set the width and height of the design draft before use, the width and height of the design draft (unit px).  
50 -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: 46 +Please set the size of the design draft before use, the width and height of the design draft (unit px).
51 47
52 -```dart 48 +```
  49 +
  50 +void main() {
  51 + WidgetsFlutterBinding.ensureInitialized();
  52 + //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)
  53 + ScreenUtil.init(designSize: Size(750, 1334), allowFontScaling: false);
  54 + runApp(MyApp());
  55 +}
53 56
54 //fill in the screen size of the device in the design 57 //fill in the screen size of the device in the design
55 58
56 //default value : width : 1080px , height:1920px , allowFontScaling:false 59 //default value : width : 1080px , height:1920px , allowFontScaling:false
57 -ScreenUtil.init(context); 60 +ScreenUtil.init();
58 61
59 //If the design is based on the size of the iPhone6 ​​(iPhone6 ​​750*1334) 62 //If the design is based on the size of the iPhone6 ​​(iPhone6 ​​750*1334)
60 -ScreenUtil.init(context, width: 750, height: 1334); 63 +ScreenUtil.init(designSize: Size(750, 1334));
61 64
62 //If you want to set the font size is scaled according to the system's "font size" assist option 65 //If you want to set the font size is scaled according to the system's "font size" assist option
63 -ScreenUtil.init(context, width: 750, height: 1334, allowFontScaling: true); 66 +ScreenUtil.init(designSize: Size(750, 1334), allowFontScaling: true);
64 67
65 ``` 68 ```
66 69
@@ -77,12 +80,12 @@ ScreenUtil.init(context, width: 750, height: 1334, allowFontScaling: true); @@ -77,12 +80,12 @@ ScreenUtil.init(context, width: 750, height: 1334, allowFontScaling: true);
77 ScreenUtil().setSp(24, allowFontScalingSelf: true) (sdk>=2.6 : 24.ssp) //Adapter font(fonts will scale to respect Text Size accessibility settings) 80 ScreenUtil().setSp(24, allowFontScalingSelf: true) (sdk>=2.6 : 24.ssp) //Adapter font(fonts will scale to respect Text Size accessibility settings)
78 ScreenUtil().setSp(24, allowFontScalingSelf: false) (sdk>=2.6 : 24.nsp) //Adapter font(fonts will not scale to respect Text Size accessibility settings) 81 ScreenUtil().setSp(24, allowFontScalingSelf: false) (sdk>=2.6 : 24.nsp) //Adapter font(fonts will not scale to respect Text Size accessibility settings)
79 82
80 - ScreenUtil.pixelRatio //Device pixel density  
81 - ScreenUtil.screenWidth (sdk>=2.6 : 1.wp) //Device width  
82 - ScreenUtil.screenHeight (sdk>=2.6 : 1.hp) //Device height  
83 - ScreenUtil.bottomBarHeight //Bottom safe zone distance, suitable for buttons with full screen  
84 - ScreenUtil.statusBarHeight //Status bar height , Notch will be higher Unit px  
85 - ScreenUtil.textScaleFactor //System font scaling factor 83 + ScreenUtil().pixelRatio //Device pixel density
  84 + ScreenUtil().screenWidth (sdk>=2.6 : 1.wp) //Device width
  85 + ScreenUtil().screenHeight (sdk>=2.6 : 1.hp) //Device height
  86 + ScreenUtil().bottomBarHeight //Bottom safe zone distance, suitable for buttons with full screen
  87 + ScreenUtil().statusBarHeight //Status bar height , Notch will be higher Unit px
  88 + ScreenUtil().textScaleFactor //System font scaling factor
86 89
87 ScreenUtil().scaleWidth //Ratio of actual width dp to design draft px 90 ScreenUtil().scaleWidth //Ratio of actual width dp to design draft px
88 ScreenUtil().scaleHeight //Ratio of actual height dp to design draft px 91 ScreenUtil().scaleHeight //Ratio of actual height dp to design draft px
@@ -119,7 +122,7 @@ height:200.h @@ -119,7 +122,7 @@ height:200.h
119 ``` 122 ```
120 **Note** 123 **Note**
121 124
122 -Height is also adapted according to setWidth to ensure no deformation (when you want a square) 125 +The height can also use setWidth to ensure that it is not deformed(when you want a square)
123 126
124 setHeight method is mainly adapted in height, you want to control the height and actuality of a screen on the UIUsed when the same is displayed. 127 setHeight method is mainly adapted in height, you want to control the height and actuality of a screen on the UIUsed when the same is displayed.
125 128
@@ -135,23 +138,28 @@ Container( @@ -135,23 +138,28 @@ Container(
135 ////If you want to display a square: 138 ////If you want to display a square:
136 Container( 139 Container(
137 width: ScreenUtil().setWidth(300), 140 width: ScreenUtil().setWidth(300),
138 - height: ScreenUtil().setWidth(300), 141 + height: 300.w,
139 ), 142 ),
140 - 143 +
141 ``` 144 ```
142 145
143 #### Adapter font: 146 #### Adapter font:
144 ``` dart 147 ``` dart
145 //Incoming font size,the unit is pixel, fonts will not scale to respect Text Size accessibility settings 148 //Incoming font size,the unit is pixel, fonts will not scale to respect Text Size accessibility settings
146 //(AllowallowFontScaling when initializing ScreenUtil) 149 //(AllowallowFontScaling when initializing ScreenUtil)
147 -ScreenUtil().setSp(28) 150 +ScreenUtil().setSp(28)
  151 +28.sp
148 152
149 //Incoming font size,the unit is pixel,fonts will scale to respect Text Size accessibility settings 153 //Incoming font size,the unit is pixel,fonts will scale to respect Text Size accessibility settings
150 -//(If somewhere does not follow the global allowFontScaling setting) 154 +//(If somewhere follow the global allowFontScaling setting)
151 ScreenUtil().setSp(24, allowFontScalingSelf: true) 155 ScreenUtil().setSp(24, allowFontScalingSelf: true)
  156 +28.ssp
152 157
153 -//for example: 158 +//(If somewhere does not follow the global allowFontScaling setting)
  159 +ScreenUtil().setSp(24, allowFontScalingSelf: false)
  160 +28.nsp
154 161
  162 +//for example:
155 Column( 163 Column(
156 crossAxisAlignment: CrossAxisAlignment.start, 164 crossAxisAlignment: CrossAxisAlignment.start,
157 children: <Widget>[ 165 children: <Widget>[
@@ -171,167 +179,11 @@ Column( @@ -171,167 +179,11 @@ Column(
171 ) 179 )
172 ``` 180 ```
173 181
174 -```dart  
175 -//import  
176 -import 'package:flutter/material.dart';  
177 -import 'package:flutter_screenutil/flutter_screenutil.dart';  
178 -  
179 -void main() => runApp(MyApp());  
180 -  
181 -class MyApp extends StatelessWidget {  
182 - @override  
183 - Widget build(BuildContext context) {  
184 - return MaterialApp(  
185 - debugShowCheckedModeBanner: false,  
186 - title: 'Flutter_ScreenUtil',  
187 - theme: ThemeData(  
188 - primarySwatch: Colors.blue,  
189 - ),  
190 - home: MyHomePage(),  
191 - );  
192 - }  
193 -}  
194 -  
195 -class MyHomePage extends StatefulWidget {  
196 - @override  
197 - _MyHomePageState createState() => _MyHomePageState();  
198 -}  
199 -  
200 -class _MyHomePageState extends State<MyHomePage> {  
201 - @override  
202 - Widget build(BuildContext context) {  
203 - //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)  
204 - ScreenUtil.init(width: 750, height: 1334, allowFontScaling: false);  
205 -  
206 - return ExampleWidget(title: 'FlutterScreenUtil Demo');  
207 - }  
208 -}  
209 -  
210 -class ExampleWidget extends StatefulWidget {  
211 - const ExampleWidget({Key key, this.title}) : super(key: key);  
212 -  
213 - final String title;  
214 -  
215 - @override  
216 - _ExampleWidgetState createState() => _ExampleWidgetState();  
217 -}  
218 -  
219 -class _ExampleWidgetState extends State<ExampleWidget> {  
220 - @override  
221 - Widget build(BuildContext context) {  
222 - printScreenInformation();  
223 - return Scaffold(  
224 - appBar: AppBar(  
225 - title: Text(widget.title),  
226 - ),  
227 - body: SingleChildScrollView(  
228 - child: Column(  
229 - crossAxisAlignment: CrossAxisAlignment.center,  
230 - children: <Widget>[  
231 - Row(  
232 - children: <Widget>[  
233 - Container(  
234 - padding: EdgeInsets.all(ScreenUtil().setWidth(10)),  
235 - width: ScreenUtil().setWidth(375),  
236 - height: ScreenUtil().setHeight(200),  
237 - color: Colors.red,  
238 - child: Text(  
239 - 'My width:${ScreenUtil().setWidth(375)}dp \n'  
240 - 'My height:${ScreenUtil().setHeight(200)}dp',  
241 - style: TextStyle(  
242 - color: Colors.white, fontSize: ScreenUtil().setSp(24)),  
243 - ),  
244 - ),  
245 - Container(  
246 - padding: EdgeInsets.all(ScreenUtil().setWidth(10)),  
247 - width: ScreenUtil().setWidth(375),  
248 - height: ScreenUtil().setHeight(200),  
249 - color: Colors.blue,  
250 - child: Text(  
251 - 'My width:${ScreenUtil().setWidth(375)}dp \n'  
252 - 'My height:${ScreenUtil().setHeight(200)}dp',  
253 - style: TextStyle(  
254 - color: Colors.white,  
255 - fontSize: ScreenUtil().setSp(24))),  
256 - ),  
257 - ],  
258 - ),  
259 - Text('Device width:${ScreenUtil.screenWidth}dp'),  
260 - Text('Device height:${ScreenUtil.screenHeight}dp'),  
261 - Text('Device width:${ScreenUtil.screenWidthPx}px'),  
262 - Text('Device height:${ScreenUtil.screenHeightPx}px'),  
263 - Text('Device pixel density:${ScreenUtil.pixelRatio}'),  
264 - Text('Bottom safe zone distance:${ScreenUtil.bottomBarHeight}dp'),  
265 - Text('Status bar height:${ScreenUtil.statusBarHeight}dp'),  
266 - Text(  
267 - 'Ratio of actual width dp to design draft px:${ScreenUtil().scaleWidth}',  
268 - textAlign: TextAlign.center,  
269 - ),  
270 - Text(  
271 - 'Ratio of actual height dp to design draft px:${ScreenUtil().scaleHeight}',  
272 - textAlign: TextAlign.center,  
273 - ),  
274 - SizedBox(  
275 - height: ScreenUtil().setHeight(100),  
276 - ),  
277 - Text('System font scaling factor:${ScreenUtil.textScaleFactor}'),  
278 - Column(  
279 - crossAxisAlignment: CrossAxisAlignment.start,  
280 - children: <Widget>[  
281 - Text(  
282 - 'My font size is 24px on the design draft and will not change with the system.',  
283 - style: TextStyle(  
284 - color: Colors.black,  
285 - fontSize: ScreenUtil().setSp(24),  
286 - )),  
287 - Text(  
288 - 'My font size is 24px on the design draft and will change with the system.',  
289 - style: TextStyle(  
290 - color: Colors.black,  
291 - fontSize: ScreenUtil()  
292 - .setSp(24, allowFontScalingSelf: true))),  
293 - ],  
294 - )  
295 - ],  
296 - ),  
297 - ),  
298 - floatingActionButton: FloatingActionButton(  
299 - child: Icon(Icons.title),  
300 - onPressed: () {  
301 - ScreenUtil.init(width: 1500, height: 1334, allowFontScaling: false);  
302 - setState(() {});  
303 - },  
304 - ),  
305 - );  
306 - }  
307 -  
308 - void printScreenInformation() {  
309 - print('Device width dp:${ScreenUtil.screenWidth}'); //Device width  
310 - print('Device height dp:${ScreenUtil.screenHeight}'); //Device height  
311 - print(  
312 - 'Device pixel density:${ScreenUtil.pixelRatio}'); //Device pixel density  
313 - print(  
314 - 'Bottom safe zone distance dp:${ScreenUtil.bottomBarHeight}'); //Bottom safe zone distance,suitable for buttons with full screen  
315 - print(  
316 - 'Status bar height dp:${ScreenUtil.statusBarHeight}dp'); //Status bar height , Notch will be higher Unit dp  
317 - print(  
318 - 'Ratio of actual width dp to design draft px:${ScreenUtil().scaleWidth}');  
319 - print(  
320 - 'Ratio of actual height dp to design draft px:${ScreenUtil().scaleHeight}');  
321 - print(  
322 - 'The ratio of font and width to the size of the design:${ScreenUtil().scaleWidth * ScreenUtil.pixelRatio}');  
323 - print(  
324 - 'The ratio of height width to the size of the design:${ScreenUtil().scaleHeight * ScreenUtil.pixelRatio}');  
325 - }  
326 -}  
327 -  
328 -```  
329 -  
330 -### example: 182 +### Example:
331 183
332 [example demo](/example/lib/main.dart) 184 [example demo](/example/lib/main.dart)
333 185
334 -effect: 186 +### Effect:
335 187
336 ![effect](demo_en.png) 188 ![effect](demo_en.png)
337 ![tablet effect](demo_tablet_en.png) 189 ![tablet effect](demo_tablet_en.png)
1 -  
2 # flutter_ScreenUtil 1 # flutter_ScreenUtil
3 2
4 [![pub package](https://img.shields.io/pub/v/flutter_screenutil.svg)](https://pub.dartlang.org/packages/flutter_screenutil) 3 [![pub package](https://img.shields.io/pub/v/flutter_screenutil.svg)](https://pub.dartlang.org/packages/flutter_screenutil)
5 4
6 -  
7 **flutter 屏幕适配方案,让你的UI在不同尺寸的屏幕上都能显示合理的布局!** 5 **flutter 屏幕适配方案,让你的UI在不同尺寸的屏幕上都能显示合理的布局!**
8 6
  7 +
9 *注意*:此插件仍处于开发阶段,某些API可能尚未推出。 8 *注意*:此插件仍处于开发阶段,某些API可能尚未推出。
10 9
11 [README of English](https://github.com/OpenFlutter/flutter_ScreenUtil/blob/master/README.md) 10 [README of English](https://github.com/OpenFlutter/flutter_ScreenUtil/blob/master/README.md)
@@ -36,7 +35,6 @@ dependencies: @@ -36,7 +35,6 @@ dependencies:
36 # 添加依赖 35 # 添加依赖
37 flutter_screenutil: ^2.3.0 36 flutter_screenutil: ^2.3.0
38 ``` 37 ```
39 -  
40 ### 在每个使用的地方导入包: 38 ### 在每个使用的地方导入包:
41 ``` 39 ```
42 import 'package:flutter_screenutil/flutter_screenutil.dart'; 40 import 'package:flutter_screenutil/flutter_screenutil.dart';
@@ -56,15 +54,21 @@ import 'package:flutter_screenutil/flutter_screenutil.dart'; @@ -56,15 +54,21 @@ import 'package:flutter_screenutil/flutter_screenutil.dart';
56 54
57 ``` 55 ```
58 //填入设计稿中设备的屏幕尺寸 56 //填入设计稿中设备的屏幕尺寸
  57 +void main() {
  58 + WidgetsFlutterBinding.ensureInitialized();
  59 + //设置适配尺寸 (填入设计稿中设备的屏幕尺寸) 此处假如设计稿是按iPhone6的尺寸设计的(iPhone6 750*1334)
  60 + ScreenUtil.init(designSize: Size(750, 1334), allowFontScaling: false);
  61 + runApp(MyApp());
  62 +}
59 63
60 //默认 width : 1080px , height:1920px , allowFontScaling:false 64 //默认 width : 1080px , height:1920px , allowFontScaling:false
61 -ScreenUtil.init(context); 65 +ScreenUtil.init();
62 66
63 //假如设计稿是按iPhone6的尺寸设计的(iPhone6 750*1334) 67 //假如设计稿是按iPhone6的尺寸设计的(iPhone6 750*1334)
64 -ScreenUtil.init(context, width: 750, height: 1334); 68 +ScreenUtil.init(designSize: Size(750, 1334));
65 69
66 //设置字体大小根据系统的“字体大小”辅助选项来进行缩放,默认为false 70 //设置字体大小根据系统的“字体大小”辅助选项来进行缩放,默认为false
67 -ScreenUtil.init(context, width: 750, height: 1334, allowFontScaling: true); 71 +ScreenUtil.init(designSize: Size(750, 1334), allowFontScaling: true);
68 72
69 ``` 73 ```
70 74
@@ -176,10 +180,12 @@ Column( @@ -176,10 +180,12 @@ Column(
176 ``` 180 ```
177 181
178 ```dart 182 ```dart
179 -import 'package:flutter/material.dart';  
180 -import 'package:flutter_screenutil/flutter_screenutil.dart';  
181 -  
182 -void main() => runApp( MyApp()); 183 +void main() {
  184 + WidgetsFlutterBinding.ensureInitialized();
  185 + //设置适配尺寸 (填入设计稿中设备的屏幕尺寸) 此处假如设计稿是按iPhone6的尺寸设计的(iPhone6 750*1334)
  186 + ScreenUtil.init(designSize: Size(750, 1334), allowFontScaling: false);
  187 + runApp(MyApp());
  188 +}
183 189
184 class MyApp extends StatelessWidget { 190 class MyApp extends StatelessWidget {
185 @override 191 @override
@@ -190,30 +196,11 @@ class MyApp extends StatelessWidget { @@ -190,30 +196,11 @@ class MyApp extends StatelessWidget {
190 theme: ThemeData( 196 theme: ThemeData(
191 primarySwatch: Colors.blue, 197 primarySwatch: Colors.blue,
192 ), 198 ),
193 - home: MyHomePage(), 199 + home: ExampleWidget(title: 'FlutterScreenUtil示例'),
194 ); 200 );
195 } 201 }
196 } 202 }
197 203
198 -class MyHomePage extends StatefulWidget {  
199 - MyHomePage({Key key, this.title}) : super(key: key);  
200 -  
201 - final String title;  
202 -  
203 - @override  
204 - _MyHomePageState createState() => _MyHomePageState();  
205 -}  
206 -  
207 -class _MyHomePageState extends State<MyHomePage> {  
208 - @override  
209 - Widget build(BuildContext context) {  
210 - //设置适配尺寸 (填入设计稿中设备的屏幕尺寸) 此处假如设计稿是按iPhone6的尺寸设计的(iPhone6 750*1334)  
211 - ScreenUtil.init(context, width: 750, height: 1334, allowFontScaling: false);  
212 -  
213 - return ExampleWidget(title: 'FlutterScreenUtil示例');  
214 - }  
215 -}  
216 -  
217 class ExampleWidget extends StatefulWidget { 204 class ExampleWidget extends StatefulWidget {
218 const ExampleWidget({Key key, this.title}) : super(key: key); 205 const ExampleWidget({Key key, this.title}) : super(key: key);
219 206
@@ -243,7 +230,7 @@ class _ExampleWidgetState extends State<ExampleWidget> { @@ -243,7 +230,7 @@ class _ExampleWidgetState extends State<ExampleWidget> {
243 height: ScreenUtil().setHeight(200), 230 height: ScreenUtil().setHeight(200),
244 color: Colors.red, 231 color: Colors.red,
245 child: Text( 232 child: Text(
246 - '我的宽度:${ScreenUtil().setWidth(375)}dp \n' 233 + '我的宽度:${0.5.wp}dp \n'
247 '我的高度:${ScreenUtil().setHeight(200)}dp', 234 '我的高度:${ScreenUtil().setHeight(200)}dp',
248 style: TextStyle( 235 style: TextStyle(
249 color: Colors.white, fontSize: ScreenUtil().setSp(24)), 236 color: Colors.white, fontSize: ScreenUtil().setSp(24)),
@@ -251,25 +238,25 @@ class _ExampleWidgetState extends State<ExampleWidget> { @@ -251,25 +238,25 @@ class _ExampleWidgetState extends State<ExampleWidget> {
251 ), 238 ),
252 Container( 239 Container(
253 padding: EdgeInsets.all(ScreenUtil().setWidth(10)), 240 padding: EdgeInsets.all(ScreenUtil().setWidth(10)),
254 - width: ScreenUtil().setWidth(375),  
255 - height: ScreenUtil().setHeight(200), 241 + width: 375.w,
  242 + height: 200.h,
256 color: Colors.blue, 243 color: Colors.blue,
257 child: Text( 244 child: Text(
258 - '我的宽度:${ScreenUtil().setWidth(375)}dp \n'  
259 - '我的高度:${ScreenUtil().setHeight(200)}dp', 245 + '我的宽度:${375.w}dp \n'
  246 + '我的高度:${200.h}dp',
260 style: TextStyle( 247 style: TextStyle(
261 color: Colors.white, 248 color: Colors.white,
262 fontSize: ScreenUtil().setSp(24))), 249 fontSize: ScreenUtil().setSp(24))),
263 ), 250 ),
264 ], 251 ],
265 ), 252 ),
266 - Text('设备宽度:${ScreenUtil.screenWidth}dp'),  
267 - Text('设备高度:${ScreenUtil.screenHeight}dp'),  
268 - Text('设备宽度:${ScreenUtil.screenWidthPx}px'),  
269 - Text('设备高度:${ScreenUtil.screenHeightPx}px'),  
270 - Text('设备的像素密度:${ScreenUtil.pixelRatio}'),  
271 - Text('底部安全区距离:${ScreenUtil.bottomBarHeight}dp'),  
272 - Text('状态栏高度:${ScreenUtil.statusBarHeight}dp'), 253 + Text('设备宽度:${ScreenUtil().screenWidthPx}px'),
  254 + Text('设备高度:${ScreenUtil().screenHeightPx}px'),
  255 + Text('设备宽度:${ScreenUtil().screenWidth}dp'),
  256 + Text('设备高度:${ScreenUtil().screenHeight}dp'),
  257 + Text('设备的像素密度:${ScreenUtil().pixelRatio}'),
  258 + Text('底部安全区距离:${ScreenUtil().bottomBarHeight}dp'),
  259 + Text('状态栏高度:${ScreenUtil().statusBarHeight}dp'),
273 Text( 260 Text(
274 '实际宽度的dp与设计稿px的比例:${ScreenUtil().scaleWidth}', 261 '实际宽度的dp与设计稿px的比例:${ScreenUtil().scaleWidth}',
275 textAlign: TextAlign.center, 262 textAlign: TextAlign.center,
@@ -279,22 +266,20 @@ class _ExampleWidgetState extends State<ExampleWidget> { @@ -279,22 +266,20 @@ class _ExampleWidgetState extends State<ExampleWidget> {
279 textAlign: TextAlign.center, 266 textAlign: TextAlign.center,
280 ), 267 ),
281 SizedBox( 268 SizedBox(
282 - height: ScreenUtil().setHeight(100), 269 + height: 100.h,
283 ), 270 ),
284 - Text('系统的字体缩放比例:${ScreenUtil.textScaleFactor}'), 271 + Text('系统的字体缩放比例:${ScreenUtil().textScaleFactor}'),
285 Column( 272 Column(
286 crossAxisAlignment: CrossAxisAlignment.start, 273 crossAxisAlignment: CrossAxisAlignment.start,
287 children: <Widget>[ 274 children: <Widget>[
288 - Text('我的文字大小在设计稿上是24px,不会随着系统的文字缩放比例变化',  
289 - style: TextStyle(  
290 - color: Colors.black,  
291 - fontSize: ScreenUtil().setSp(24),  
292 - )),  
293 - Text('我的文字大小在设计稿上是24px,会随着系统的文字缩放比例变化',  
294 - style: TextStyle(  
295 - color: Colors.black,  
296 - fontSize: ScreenUtil()  
297 - .setSp(24, allowFontScalingSelf: true))), 275 + Text(
  276 + '我的文字大小在设计稿上是24px,不会随着系统的文字缩放比例变化',
  277 + style: ts.t2,
  278 + ),
  279 + Text(
  280 + '我的文字大小在设计稿上是24px,会随着系统的文字缩放比例变化',
  281 + style: ts.t1,
  282 + ),
298 ], 283 ],
299 ) 284 )
300 ], 285 ],
@@ -303,7 +288,10 @@ class _ExampleWidgetState extends State<ExampleWidget> { @@ -303,7 +288,10 @@ class _ExampleWidgetState extends State<ExampleWidget> {
303 floatingActionButton: FloatingActionButton( 288 floatingActionButton: FloatingActionButton(
304 child: Icon(Icons.title), 289 child: Icon(Icons.title),
305 onPressed: () { 290 onPressed: () {
306 - ScreenUtil.init(width: 1500, height: 1334, allowFontScaling: false); 291 + ScreenUtil.init(
  292 + designSize: Size(1500, 1334),
  293 + allowFontScaling: false,
  294 + );
307 setState(() {}); 295 setState(() {});
308 }, 296 },
309 ), 297 ),
@@ -311,20 +299,29 @@ class _ExampleWidgetState extends State<ExampleWidget> { @@ -311,20 +299,29 @@ class _ExampleWidgetState extends State<ExampleWidget> {
311 } 299 }
312 300
313 void printScreenInformation() { 301 void printScreenInformation() {
314 - print('设备宽度:${ScreenUtil.screenWidth}'); //Device width  
315 - print('设备高度:${ScreenUtil.screenHeight}'); //Device height  
316 - print('设备的像素密度:${ScreenUtil.pixelRatio}'); //Device pixel density 302 + print('设备宽度:${ScreenUtil().screenWidth}'); //Device width
  303 + print('设备高度:${ScreenUtil().screenHeight}'); //Device height
  304 + print('设备的像素密度:${ScreenUtil().pixelRatio}'); //Device pixel density
317 print( 305 print(
318 - '底部安全区距离:${ScreenUtil.bottomBarHeight}dp'); //Bottom safe zone distance,suitable for buttons with full screen 306 + '底部安全区距离:${ScreenUtil().bottomBarHeight}dp',
  307 + ); //Bottom safe zone distance,suitable for buttons with full screen
319 print( 308 print(
320 - '状态栏高度:${ScreenUtil.statusBarHeight}dp'); //状态栏高度 , 刘海屏会更高,单位dp 309 + '状态栏高度:${ScreenUtil().statusBarHeight}dp',
  310 + ); //Status bar height , Notch will be higher Unit px
321 311
322 print('实际宽度的dp与设计稿px的比例:${ScreenUtil().scaleWidth}'); 312 print('实际宽度的dp与设计稿px的比例:${ScreenUtil().scaleWidth}');
323 print('实际高度的dp与设计稿px的比例:${ScreenUtil().scaleHeight}'); 313 print('实际高度的dp与设计稿px的比例:${ScreenUtil().scaleHeight}');
  314 +
324 print( 315 print(
325 - '宽度和字体相对于设计稿放大的比例:${ScreenUtil().scaleWidth * ScreenUtil.pixelRatio}');  
326 - print('高度相对于设计稿放大的比例:${ScreenUtil().scaleHeight * ScreenUtil.pixelRatio}');  
327 - print('系统的字体缩放比例:${ScreenUtil.textScaleFactor}'); 316 + '宽度和字体相对于设计稿放大的比例:${ScreenUtil().scaleWidth * ScreenUtil().pixelRatio}',
  317 + );
  318 + print(
  319 + '高度相对于设计稿放大的比例:${ScreenUtil().scaleHeight * ScreenUtil().pixelRatio}',
  320 + );
  321 + print('系统的字体缩放比例:${ScreenUtil().textScaleFactor}');
  322 +
  323 + print('屏幕宽度的0.5:${0.5.wp}');
  324 + print('屏幕高度的0.5:${0.5.hp}');
328 } 325 }
329 } 326 }
330 327
1 -  
2 # flutter_screenutil 1 # flutter_screenutil
3 [![pub package](https://img.shields.io/pub/v/flutter_screenutil.svg)](https://pub.dartlang.org/packages/flutter_screenutil) 2 [![pub package](https://img.shields.io/pub/v/flutter_screenutil.svg)](https://pub.dartlang.org/packages/flutter_screenutil)
4 3
@@ -50,17 +49,22 @@ Por favor, defina a largura e altura do protótipo de design antes de usar (em p @@ -50,17 +49,22 @@ Por favor, defina a largura e altura do protótipo de design antes de usar (em p
50 Certifique-se de definir as dimensões na paginal inicial do MaterialApp (ou seja, no arquivo de entrada, defina apenas uma vez) para garantir que o tamanho de ajuste seja o mesmo antes de cada uso: 49 Certifique-se de definir as dimensões na paginal inicial do MaterialApp (ou seja, no arquivo de entrada, defina apenas uma vez) para garantir que o tamanho de ajuste seja o mesmo antes de cada uso:
51 50
52 ```dart 51 ```dart
53 -  
54 //Preencha o tamanho da tela do dispositivo no protótipo de design 52 //Preencha o tamanho da tela do dispositivo no protótipo de design
  53 +void main() {
  54 + WidgetsFlutterBinding.ensureInitialized();
  55 + //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)
  56 + ScreenUtil.init(designSize: Size(750, 1334), allowFontScaling: false);
  57 + runApp(MyApp());
  58 +}
55 59
56 //Valor padrão: width : 1080px , height:1920px , allowFontScaling:false 60 //Valor padrão: width : 1080px , height:1920px , allowFontScaling:false
57 -ScreenUtil.init(context); 61 +ScreenUtil.init();
58 62
59 //Se o design é baseado no iPhone6 ​​(iPhone6 ​​750*1334) 63 //Se o design é baseado no iPhone6 ​​(iPhone6 ​​750*1334)
60 -ScreenUtil.init(context, width: 750, height: 1334); 64 +ScreenUtil.init(designSize: Size(750, 1334));
61 65
62 //Se você quer definir que o tamanho da fonte seja ajustado de acordo com a opção "tamanho da fonte" na acessibilidade do sistema 66 //Se você quer definir que o tamanho da fonte seja ajustado de acordo com a opção "tamanho da fonte" na acessibilidade do sistema
63 -ScreenUtil.init(context, width: 750, height: 1334, allowFontScaling: true); 67 +ScreenUtil.init(designSize: Size(750, 1334), allowFontScaling: true);
64 68
65 ``` 69 ```
66 70
@@ -145,4 +149,160 @@ Container( @@ -145,4 +149,160 @@ Container(
145 ScreenUtil().setSp(28) 149 ScreenUtil().setSp(28)
146 150
147 //Tamanho da fonte informado,em pixels,a fonte irá dimensionar respeitando a opção "Tamanho de Fonte" nas configurações de acessibilidade 151 //Tamanho da fonte informado,em pixels,a fonte irá dimensionar respeitando a opção "Tamanho de Fonte" nas configurações de acessibilidade
148 -//(Se em algum lugar não seguir a configuração global da propriedade allowFontScaling 152 +//(Se em algum lugar não seguir a configuração global da propriedade allowFontScaling)
  153 +ScreenUtil().setSp(24, allowFontScalingSelf: true)
  154 +
  155 +//Exemplo:
  156 +
  157 +Column(
  158 + crossAxisAlignment: CrossAxisAlignment.start,
  159 + children: <Widget>[
  160 + Text(
  161 + 'Minha fonte tem 24px no protótipo de design e não irá mudar com o sistema.',
  162 + style: TextStyle(
  163 + color: Colors.black,
  164 + fontSize: ScreenUtil().setSp(24),
  165 + )),
  166 + Text(
  167 + 'Minha fonte tem 24px no protótipo de design e poderá mudar com o sistema.',
  168 + style: TextStyle(
  169 + color: Colors.black,
  170 + fontSize: ScreenUtil()
  171 + .setSp(24, allowFontScalingSelf: true))),
  172 + ],
  173 + )
  174 +```
  175 +
  176 +#### Outras APIs relacionadas:
  177 +```dart
  178 + ScreenUtil.pixelRatio //Densidade de pixels do dispositivo
  179 + ScreenUtil.screenWidth //Largura da tela do dispositivo
  180 + ScreenUtil.screenHeight //Altura da tela do dispositivo
  181 + ScreenUtil.bottomBarHeight //Distância segura do rodapé, adequada para botões em tela cheia
  182 + ScreenUtil.statusBarHeight //Altura da status bar em pixels, Notch será maior
  183 + ScreenUtil.textScaleFactor //Fator de escala da fonte do sistema
  184 +
  185 + ScreenUtil().scaleWidth //Razão entre a largura atual e a largura do protótipo de design em pixels
  186 + ScreenUtil().scaleHeight //Razão entre a altura atual e a altura do protótipo de design em pixels
  187 +
  188 +```
  189 +
  190 +```dart
  191 +//import
  192 +import 'package:flutter_screenutil/flutter_screenutil.dart';
  193 +
  194 +...
  195 +
  196 + @override
  197 + Widget build(BuildContext context) {
  198 + ///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)
  199 + ScreenUtil.init(designSize: Size(750, 1334), allowFontScaling: false);
  200 +
  201 + print('Largura do dispositivo:${ScreenUtil().screenWidth}'); //Largura do dispositivo
  202 + print('Altura do dispositivo:${ScreenUtil().screenHeight}'); //Altura do dispositivo
  203 + print(
  204 + 'Densidade de pixels do dispositivo:${ScreenUtil().pixelRatio}'); //Densidade de pixels do dispositivo
  205 + print(
  206 + 'Distância segura do rodapé:${ScreenUtil().bottomBarHeight}'); //Distância segura do rodapé, adequada para botões em tela cheia
  207 + print(
  208 + 'Altura da status bar:${ScreenUtil().statusBarHeight}px'); //Altura da status bar em pixels, Notch será maior
  209 + print(
  210 + 'Razão entre a largura atual e a largura do protótipo de design em pixels:${ScreenUtil().scaleWidth}');
  211 + print(
  212 + 'Razão entre a altura atual e a altura do protótipo de design em pixels:${ScreenUtil().scaleHeight}');
  213 + print(
  214 + 'Razão da fonte e largura para o tamanho do design:${ScreenUtil().scaleWidth * ScreenUtil.pixelRatio}');
  215 + print(
  216 + 'Razão da fonte e altura para o tamanho do design:${ScreenUtil().scaleHeight * ScreenUtil.pixelRatio}');
  217 +
  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 + 'Minha largura:${ScreenUtil().setWidth(375)}dp',
  235 + style: TextStyle(
  236 + color: Colors.white,
  237 + fontSize: ScreenUtil().setSp(12)),
  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('Minha largura:${ScreenUtil().setWidth(375)}dp',
  246 + style: TextStyle(
  247 + color: Colors.white,
  248 + fontSize: ScreenUtil().setSp(12))),
  249 + ),
  250 + ],
  251 + ),
  252 + Text('Largura do dispositivo:${ScreenUtil().screenWidth}dp'),
  253 + Text('Altura do dispositivo:${ScreenUtil().screenHeight}dp'),
  254 + Text('Densidade de pixels do dispositivo:${ScreenUtil().pixelRatio}'),
  255 + Text('Distância segura do rodapé:${ScreenUtil().bottomBarHeight}dp'),
  256 + Text('Altura da status bar:${ScreenUtil().statusBarHeight}dp'),
  257 + Text(
  258 + 'Razão entre a largura atual e a largura do protótipo de design em pixels:${ScreenUtil().scaleWidth}',
  259 + textAlign: TextAlign.center,
  260 + ),
  261 + Text(
  262 + 'Razão entre a altura atual e a altura do protótipo de design em pixels:${ScreenUtil().scaleHeight}',
  263 + textAlign: TextAlign.center,
  264 + ),
  265 + Text(
  266 + 'Razão da fonte e largura para o tamanho do design:${ScreenUtil().scaleWidth * ScreenUtil.pixelRatio}',
  267 + textAlign: TextAlign.center,
  268 + ),
  269 + Text(
  270 + 'Razão da fonte e altura para o tamanho do design:${ScreenUtil().scaleHeight * ScreenUtil.pixelRatio}',
  271 + textAlign: TextAlign.center,
  272 + ),
  273 + SizedBox(
  274 + height: ScreenUtil().setHeight(100),
  275 + ),
  276 + Text('Fator de escala da fonte do sistema:${ScreenUtil.textScaleFactor}'),
  277 + Column(
  278 + crossAxisAlignment: CrossAxisAlignment.start,
  279 + children: <Widget>[
  280 + Text(
  281 + 'Minha fonte tem 24px no protótipo de design e não irá mudar com o sistema.',
  282 + style: TextStyle(
  283 + color: Colors.black,
  284 + fontSize: ScreenUtil().setSp(24),
  285 + )),
  286 + Text(
  287 + 'Minha fonte tem 24px no protótipo de design e poderá mudar com o sistema.',
  288 + style: TextStyle(
  289 + color: Colors.black,
  290 + fontSize: ScreenUtil().setSp(24, allowFontScalingSelf: true),
  291 + )),
  292 + ],
  293 + )
  294 + ],
  295 + ),
  296 + ),
  297 + );
  298 + }
  299 +```
  300 +
  301 +### Exemplo:
  302 +
  303 +[Demonstração](/example/lib/main_zh.dart)
  304 +
  305 +Efeito:
  306 +
  307 +![效果](demo_en.png)
  308 +![tablet effect](demo_tablet_en.png)
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"
  12 +export "DART_OBFUSCATION=false"
  13 +export "TRACK_WIDGET_CREATION=false"
  14 +export "TREE_SHAKE_ICONS=false"
  15 +export "PACKAGE_CONFIG=.packages"
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(750, 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(750, 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  
4 -homepage: https://github.com/OpenFlutter/flutter_screenutil 3 +version: 3.0.0-beta.2
  4 +homepage: https://github.com/OpenFlutter/flutter_screenutil/tree/beta
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