diff --git a/.packages b/.packages index 896d37f..9e745b8 100644 --- a/.packages +++ b/.packages @@ -1,4 +1,4 @@ -# Generated by pub on 2019-01-11 11:09:46.258394. +# Generated by pub on 2019-02-21 15:24:09.886695. async:file:///D:/flutter/.pub-cache/hosted/pub.dartlang.org/async-2.0.8/lib/ boolean_selector:file:///D:/flutter/.pub-cache/hosted/pub.dartlang.org/boolean_selector-1.0.4/lib/ charcode:file:///D:/flutter/.pub-cache/hosted/pub.dartlang.org/charcode-1.1.2/lib/ diff --git a/CHANGELOG.md b/CHANGELOG.md index 21e4162..870ed37 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -31,3 +31,7 @@ setSp(int fontSize, [allowFontScaling = false]) => allowFontScaling : setWidth(fontSize); ## [0.4.4] - Fix bugs that default fonts change with the system + +## [0.5.0] - Fix the wrong way of using + +please use `ScreenUtil.getInstance()` instead of `ScreenUtil()` , for example: ScreenUtil.getInstance().setHeight(25) instead of `ScreenUtil().setHeight(25)` \ No newline at end of file diff --git a/README.md b/README.md index 98c645d..5506f6d 100644 --- a/README.md +++ b/README.md @@ -46,7 +46,7 @@ Be sure to set the page in the MaterialApp's home(ie the entry file, just set it //fill in the screen size of the device in the design //default value : width : 1080px , height:1920px , allowFontScaling:false -ScreenUtil.instance = ScreenUtil()..init(context); +ScreenUtil.instance = ScreenUtil.getInstance()..init(context); //If the design is based on the size of the iPhone6 ​​(iPhone6 ​​750*1334) ScreenUtil.instance = ScreenUtil(width: 750, height: 1334)..init(context); @@ -62,11 +62,9 @@ ScreenUtil.instance = ScreenUtil(width: 750, height: 1334, allowFontScaling: tru Pass the px size of the design draft: -Adapted to screen width: `ScreenUtil().setWidth(540)`, +Adapted to screen width: `ScreenUtil.getInstance().setWidth(540)`, -Adapted to screen height: `ScreenUtil().setHeight(200)`, - -You can also use `ScreenUtil.getInstance()` instead of `ScreenUtil()` , for example: `ScreenUtil.getInstance().setHeight(25)` +Adapted to screen height: `ScreenUtil.getInstance().setHeight(200)`, **Note** @@ -78,15 +76,15 @@ setHeight method is mainly adapted in height, you want to control the height and //for example: //rectangle Container( - width: ScreenUtil().setWidth(375), - height: ScreenUtil().setHeight(200), + width: ScreenUtil.getInstance().setWidth(375), + height: ScreenUtil.getInstance().setHeight(200), ... ), ////If you want to display a square: Container( - width: ScreenUtil().setWidth(300), - height: ScreenUtil().setWidth(300), + width: ScreenUtil.getInstance().setWidth(300), + height: ScreenUtil.getInstance().setWidth(300), ), ``` @@ -95,7 +93,7 @@ Container( ``` //Incoming font size,the unit is pixel, fonts will not scale to respect Text Size accessibility settings //(AllowallowFontScaling when initializing ScreenUtil) -ScreenUtil().setSp(28) +ScreenUtil.getInstance().setSp(28) //Incoming font size,the unit is pixel,fonts will scale to respect Text Size accessibility settings //(If somewhere does not follow the global allowFontScaling setting) @@ -110,7 +108,7 @@ Column( 'My font size is 24px on the design draft and will not change with the system.', style: TextStyle( color: Colors.black, - fontSize: ScreenUtil().setSp(24), + fontSize: ScreenUtil.getInstance().setSp(24), )), Text( 'My font size is 24px on the design draft and will change with the system.', @@ -133,8 +131,8 @@ Column( ScreenUtil.statusBarHeight //Status bar height , Notch will be higher Unit px ScreenUtil.textScaleFactory //System font scaling factor - ScreenUtil().scaleWidth //Ratio of actual width dp to design draft px - ScreenUtil().scaleHeight //Ratio of actual height dp to design draft px + ScreenUtil.getInstance().scaleWidth //Ratio of actual width dp to design draft px + ScreenUtil.getInstance().scaleHeight //Ratio of actual height dp to design draft px ``` @@ -157,13 +155,13 @@ import 'package:flutter_screenutil/flutter_screenutil.dart'; print( 'Status bar height:${ScreenUtil.statusBarHeight}px'); //Status bar height , Notch will be higher Unit px print( - 'Ratio of actual width dp to design draft px:${ScreenUtil().scaleWidth}'); + 'Ratio of actual width dp to design draft px:${ScreenUtil.getInstance().scaleWidth}'); print( - 'Ratio of actual height dp to design draft px:${ScreenUtil().scaleHeight}'); + 'Ratio of actual height dp to design draft px:${ScreenUtil.getInstance().scaleHeight}'); print( - 'The ratio of font and width to the size of the design:${ScreenUtil().scaleWidth * ScreenUtil.pixelRatio}'); + 'The ratio of font and width to the size of the design:${ScreenUtil.getInstance().scaleWidth * ScreenUtil.pixelRatio}'); print( - 'The ratio of height width to the size of the design:${ScreenUtil().scaleHeight * ScreenUtil.pixelRatio}'); + 'The ratio of height width to the size of the design:${ScreenUtil.getInstance().scaleHeight * ScreenUtil.pixelRatio}'); return new Scaffold( appBar: new AppBar( title: new Text(widget.title), @@ -175,24 +173,24 @@ import 'package:flutter_screenutil/flutter_screenutil.dart'; Row( children: [ Container( - width: ScreenUtil().setWidth(375), - height: ScreenUtil().setHeight(200), + width: ScreenUtil.getInstance().setWidth(375), + height: ScreenUtil.getInstance().setHeight(200), color: Colors.red, child: Text( - 'My width:${ScreenUtil().setWidth(375)}dp', + 'My width:${ScreenUtil.getInstance().setWidth(375)}dp', style: TextStyle( color: Colors.white, - fontSize: ScreenUtil().setSp(12)), + fontSize: ScreenUtil.getInstance().setSp(12)), ), ), Container( - width: ScreenUtil().setWidth(375), - height: ScreenUtil().setHeight(200), + width: ScreenUtil.getInstance().setWidth(375), + height: ScreenUtil.getInstance().setHeight(200), color: Colors.blue, - child: Text('My width:${ScreenUtil().setWidth(375)}dp', + child: Text('My width:${ScreenUtil.getInstance().setWidth(375)}dp', style: TextStyle( color: Colors.white, - fontSize: ScreenUtil().setSp(12))), + fontSize: ScreenUtil.getInstance().setSp(12))), ), ], ), @@ -202,23 +200,23 @@ import 'package:flutter_screenutil/flutter_screenutil.dart'; Text('Bottom safe zone distance:${ScreenUtil.bottomBarHeight}px'), Text('Status bar height:${ScreenUtil.statusBarHeight}px'), Text( - 'Ratio of actual width dp to design draft px:${ScreenUtil().scaleWidth}', + 'Ratio of actual width dp to design draft px:${ScreenUtil.getInstance().scaleWidth}', textAlign: TextAlign.center, ), Text( - 'Ratio of actual height dp to design draft px:${ScreenUtil().scaleHeight}', + 'Ratio of actual height dp to design draft px:${ScreenUtil.getInstance().scaleHeight}', textAlign: TextAlign.center, ), Text( - 'The ratio of font and width to the size of the design:${ScreenUtil().scaleWidth * ScreenUtil.pixelRatio}', + 'The ratio of font and width to the size of the design:${ScreenUtil.getInstance().scaleWidth * ScreenUtil.pixelRatio}', textAlign: TextAlign.center, ), Text( - 'The ratio of height width to the size of the design:${ScreenUtil().scaleHeight * ScreenUtil.pixelRatio}', + 'The ratio of height width to the size of the design:${ScreenUtil.getInstance().scaleHeight * ScreenUtil.pixelRatio}', textAlign: TextAlign.center, ), SizedBox( - height: ScreenUtil().setHeight(100), + height: ScreenUtil.getInstance().setHeight(100), ), Text('System font scaling factor:${ScreenUtil.textScaleFactory}'), Column( @@ -228,7 +226,7 @@ import 'package:flutter_screenutil/flutter_screenutil.dart'; 'My font size is 14px on the design draft and will not change with the system.', style: TextStyle( color: Colors.black, - fontSize: ScreenUtil().setSp(14), + fontSize: ScreenUtil.getInstance().setSp(14), )), Text( 'My font size is 14px on the design draft and will change with the system.', diff --git a/README_CN.md b/README_CN.md index 4780578..4f0f0cc 100644 --- a/README_CN.md +++ b/README_CN.md @@ -26,7 +26,7 @@ dependencies: flutter: sdk: flutter # 添加依赖 - flutter_screenutil: ^0.4.2 + flutter_screenutil: ^0.5.0 ``` ### 在每个使用的地方导入包: @@ -50,7 +50,7 @@ import 'package:flutter_screenutil/flutter_screenutil.dart'; //填入设计稿中设备的屏幕尺寸 //默认 width : 1080px , height:1920px , allowFontScaling:false -ScreenUtil.instance = ScreenUtil()..init(context); +ScreenUtil.instance = ScreenUtil.getInstance()..init(context); //假如设计稿是按iPhone6的尺寸设计的(iPhone6 750*1334) ScreenUtil.instance = ScreenUtil(width: 750, height: 1334)..init(context); @@ -66,11 +66,10 @@ ScreenUtil.instance = ScreenUtil(width: 750, height: 1334, allowFontScaling: tru 传入设计稿的px尺寸: -根据屏幕宽度适配 `width: ScreenUtil().setWidth(540)`, +根据屏幕宽度适配 `width: ScreenUtil.getInstance().setWidth(540)`, -根据屏幕高度适配 `height: ScreenUtil().setHeight(200)`, +根据屏幕高度适配 `height: ScreenUtil.getInstance().setHeight(200)`, -也可以使用 `ScreenUtil.getInstance()` 来替代`ScreenUtil()` , 例如:`ScreenUtil.getInstance().setHeight(25)` **注意** @@ -83,14 +82,14 @@ setHeight方法主要是在高度上进行适配, 在你想控制UI上一屏的 ``` //长方形: Container( - width: ScreenUtil().setWidth(375), - height: ScreenUtil().setHeight(200), + width: ScreenUtil.getInstance().setWidth(375), + height: ScreenUtil.getInstance().setHeight(200), ), //如果你想显示一个正方形: Container( - width: ScreenUtil().setWidth(300), - height: ScreenUtil().setWidth(300), + width: ScreenUtil.getInstance().setWidth(300), + height: ScreenUtil.getInstance().setWidth(300), ), ``` @@ -99,7 +98,7 @@ Container( ``` //传入字体大小,默认不根据系统的“字体大小”辅助选项来进行缩放(可在初始化ScreenUtil时设置allowFontScaling) -ScreenUtil().setSp(28) +ScreenUtil.getInstance().setSp(28) //传入字体大小,根据系统的“字体大小”辅助选项来进行缩放(如果某个地方不遵循全局的allowFontScaling设置) ScreenUtil(allowFontScaling: true).setSp(28) @@ -111,7 +110,7 @@ Column( children: [ Text('我的文字大小在设计稿上是25px,不会随着系统的文字缩放比例变化', style: TextStyle( - color: Colors.black, fontSize: ScreenUtil().setSp(24))), + color: Colors.black, fontSize: ScreenUtil.getInstance().setSp(24))), Text('我的文字大小在设计稿上是25px,会随着系统的文字缩放比例变化', style: TextStyle( color: Colors.black, fontSize: ScreenUtil(allowFontScaling: true).setSp(24))), @@ -130,8 +129,8 @@ Column( ScreenUtil.statusBarHeight //状态栏高度 刘海屏会更高 单位px ScreenUtil.textScaleFactory //系统字体缩放比例 - ScreenUtil().scaleWidth // 实际宽度的dp与设计稿px的比例 - ScreenUtil().scaleHeight // 实际高度的dp与设计稿px的比例 + ScreenUtil.getInstance().scaleWidth // 实际宽度的dp与设计稿px的比例 + ScreenUtil.getInstance().scaleHeight // 实际高度的dp与设计稿px的比例 ``` @@ -153,13 +152,13 @@ import 'package:flutter_screenutil/flutter_screenutil.dart'; print( '状态栏高度:${ScreenUtil.statusBarHeight}px'); //Status bar height , Notch will be higher Unit px - print('实际宽度的dp与设计稿px的比例:${ScreenUtil().scaleWidth}'); - print('实际高度的dp与设计稿px的比例:${ScreenUtil().scaleHeight}'); + print('实际宽度的dp与设计稿px的比例:${ScreenUtil.getInstance().scaleWidth}'); + print('实际高度的dp与设计稿px的比例:${ScreenUtil.getInstance().scaleHeight}'); print( - '宽度和字体相对于设计稿放大的比例:${ScreenUtil().scaleWidth * ScreenUtil.pixelRatio}'); + '宽度和字体相对于设计稿放大的比例:${ScreenUtil.getInstance().scaleWidth * ScreenUtil.pixelRatio}'); print( - '高度相对于设计稿放大的比例:${ScreenUtil().scaleHeight * ScreenUtil.pixelRatio}'); + '高度相对于设计稿放大的比例:${ScreenUtil.getInstance().scaleHeight * ScreenUtil.pixelRatio}'); print('系统的字体缩放比例:${ScreenUtil.textScaleFactory}'); return new Scaffold( @@ -173,25 +172,25 @@ import 'package:flutter_screenutil/flutter_screenutil.dart'; Row( children: [ Container( - width: ScreenUtil().setWidth(375), - height: ScreenUtil().setHeight(200), + width: ScreenUtil.getInstance().setWidth(375), + height: ScreenUtil.getInstance().setHeight(200), color: Colors.red, child: Text( - '我的宽度:${ScreenUtil().setWidth(375)}dp', + '我的宽度:${ScreenUtil.getInstance().setWidth(375)}dp', style: TextStyle( color: Colors.white, - fontSize: ScreenUtil().setSp(12), + fontSize: ScreenUtil.getInstance().setSp(12), ), ), ), Container( - width: ScreenUtil().setWidth(375), - height: ScreenUtil().setHeight(200), + width: ScreenUtil.getInstance().setWidth(375), + height: ScreenUtil.getInstance().setHeight(200), color: Colors.blue, - child: Text('我的宽度:${ScreenUtil().setWidth(375)}dp', + child: Text('我的宽度:${ScreenUtil.getInstance().setWidth(375)}dp', style: TextStyle( color: Colors.white, - fontSize: ScreenUtil().setSp(12), + fontSize: ScreenUtil.getInstance().setSp(12), )), ), ], @@ -202,23 +201,23 @@ import 'package:flutter_screenutil/flutter_screenutil.dart'; Text('底部安全区距离:${ScreenUtil.bottomBarHeight}px'), Text('状态栏高度:${ScreenUtil.statusBarHeight}px'), Text( - '实际高度的dp与设计稿px的比例:${ScreenUtil().scaleHeight}', + '实际高度的dp与设计稿px的比例:${ScreenUtil.getInstance().scaleHeight}', textAlign: TextAlign.center, ), Text( - '实际高度的dp与设计稿px的比例:${ScreenUtil().scaleHeight}', + '实际高度的dp与设计稿px的比例:${ScreenUtil.getInstance().scaleHeight}', textAlign: TextAlign.center, ), Text( - '宽度和字体相对于设计稿放大的比例:${ScreenUtil().scaleWidth * ScreenUtil.pixelRatio}', + '宽度和字体相对于设计稿放大的比例:${ScreenUtil.getInstance().scaleWidth * ScreenUtil.pixelRatio}', textAlign: TextAlign.center, ), Text( - '高度相对于设计稿放大的比例:${ScreenUtil().scaleHeight * ScreenUtil.pixelRatio}', + '高度相对于设计稿放大的比例:${ScreenUtil.getInstance().scaleHeight * ScreenUtil.pixelRatio}', textAlign: TextAlign.center, ), SizedBox( - height: ScreenUtil().setHeight(100), + height: ScreenUtil.getInstance().setHeight(100), ), Text('系统的字体缩放比例:${ScreenUtil.textScaleFactory}'), Column( @@ -226,7 +225,7 @@ import 'package:flutter_screenutil/flutter_screenutil.dart'; children: [ Text('我的文字大小在设计稿上是25px,不会随着系统的文字缩放比例变化', style: TextStyle( - color: Colors.black, fontSize: ScreenUtil().setSp(24))), + color: Colors.black, fontSize: ScreenUtil.getInstance().setSp(24))), Text('我的文字大小在设计稿上是25px,会随着系统的文字缩放比例变化', style: TextStyle( color: Colors.black, fontSize: ScreenUtil(allowFontScaling: true).setSp(24))), diff --git a/example/lib/main.dart b/example/lib/main.dart index 7cc90cf..03bb47f 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -42,13 +42,13 @@ class _MyHomePageState extends State { print( 'Status bar height:${ScreenUtil.statusBarHeight}px'); //Status bar height , Notch will be higher Unit px print( - 'Ratio of actual width dp to design draft px:${ScreenUtil().scaleWidth}'); + 'Ratio of actual width dp to design draft px:${ScreenUtil.getInstance().scaleWidth}'); print( - 'Ratio of actual height dp to design draft px:${ScreenUtil().scaleHeight}'); + 'Ratio of actual height dp to design draft px:${ScreenUtil.getInstance().scaleHeight}'); print( - 'The ratio of font and width to the size of the design:${ScreenUtil().scaleWidth * ScreenUtil.pixelRatio}'); + 'The ratio of font and width to the size of the design:${ScreenUtil.getInstance().scaleWidth * ScreenUtil.pixelRatio}'); print( - 'The ratio of height width to the size of the design:${ScreenUtil().scaleHeight * ScreenUtil.pixelRatio}'); + 'The ratio of height width to the size of the design:${ScreenUtil.getInstance().scaleHeight * ScreenUtil.pixelRatio}'); return new Scaffold( appBar: new AppBar( title: new Text(widget.title), @@ -60,23 +60,25 @@ class _MyHomePageState extends State { Row( children: [ Container( - width: ScreenUtil().setWidth(375), - height: ScreenUtil().setHeight(200), + width: ScreenUtil.getInstance().setWidth(375), + height: ScreenUtil.getInstance().setHeight(200), color: Colors.red, child: Text( - 'My width:${ScreenUtil().setWidth(375)}dp', + 'My width:${ScreenUtil.getInstance().setWidth(375)}dp', style: TextStyle( - color: Colors.white, fontSize: ScreenUtil().setSp(24)), + color: Colors.white, + fontSize: ScreenUtil.getInstance().setSp(24)), ), ), Container( - width: ScreenUtil().setWidth(375), - height: ScreenUtil().setHeight(200), + width: ScreenUtil.getInstance().setWidth(375), + height: ScreenUtil.getInstance().setHeight(200), color: Colors.blue, - child: Text('My width:${ScreenUtil().setWidth(375)}dp', + child: Text( + 'My width:${ScreenUtil.getInstance().setWidth(375)}dp', style: TextStyle( color: Colors.white, - fontSize: ScreenUtil().setSp(24))), + fontSize: ScreenUtil.getInstance().setSp(24))), ), ], ), @@ -86,23 +88,23 @@ class _MyHomePageState extends State { Text('Bottom safe zone distance:${ScreenUtil.bottomBarHeight}px'), Text('Status bar height:${ScreenUtil.statusBarHeight}px'), Text( - 'Ratio of actual width dp to design draft px:${ScreenUtil().scaleWidth}', + 'Ratio of actual width dp to design draft px:${ScreenUtil.getInstance().scaleWidth}', textAlign: TextAlign.center, ), Text( - 'Ratio of actual height dp to design draft px:${ScreenUtil().scaleHeight}', + 'Ratio of actual height dp to design draft px:${ScreenUtil.getInstance().scaleHeight}', textAlign: TextAlign.center, ), Text( - 'The ratio of font and width to the size of the design:${ScreenUtil().scaleWidth * ScreenUtil.pixelRatio}', + 'The ratio of font and width to the size of the design:${ScreenUtil.getInstance().scaleWidth * ScreenUtil.pixelRatio}', textAlign: TextAlign.center, ), Text( - 'The ratio of height width to the size of the design:${ScreenUtil().scaleHeight * ScreenUtil.pixelRatio}', + 'The ratio of height width to the size of the design:${ScreenUtil.getInstance().scaleHeight * ScreenUtil.pixelRatio}', textAlign: TextAlign.center, ), SizedBox( - height: ScreenUtil().setHeight(100), + height: ScreenUtil.getInstance().setHeight(100), ), Text('System font scaling factor:${ScreenUtil.textScaleFactory}'), Column( @@ -112,7 +114,7 @@ class _MyHomePageState extends State { 'My font size is 24px on the design draft and will not change with the system.', style: TextStyle( color: Colors.black, - fontSize: ScreenUtil().setSp(24), + fontSize: ScreenUtil.getInstance().setSp(24), )), Text( 'My font size is 24px on the design draft and will change with the system.', diff --git a/example/lib/main_zh.dart b/example/lib/main_zh.dart index 2cba9ab..4b61bfb 100644 --- a/example/lib/main_zh.dart +++ b/example/lib/main_zh.dart @@ -40,18 +40,26 @@ class _MyHomePageState extends State { print( '状态栏高度:${ScreenUtil.statusBarHeight}px'); //Status bar height , Notch will be higher Unit px - print('实际宽度的dp与设计稿px的比例:${ScreenUtil().scaleWidth}'); - print('实际高度的dp与设计稿px的比例:${ScreenUtil().scaleHeight}'); + print('实际宽度的dp与设计稿px的比例:${ScreenUtil.getInstance().scaleWidth}'); + print('实际高度的dp与设计稿px的比例:${ScreenUtil.getInstance().scaleHeight}'); print( - '宽度和字体相对于设计稿放大的比例:${ScreenUtil().scaleWidth * ScreenUtil.pixelRatio}'); - print('高度相对于设计稿放大的比例:${ScreenUtil().scaleHeight * ScreenUtil.pixelRatio}'); + '宽度和字体相对于设计稿放大的比例:${ScreenUtil.getInstance().scaleWidth * ScreenUtil.pixelRatio}'); + print('高度相对于设计稿放大的比例:${ScreenUtil.getInstance().scaleHeight * ScreenUtil.pixelRatio}'); print('系统的字体缩放比例:${ScreenUtil.textScaleFactory}'); return new Scaffold( appBar: new AppBar( title: new Text(widget.title), ), + floatingActionButton: FloatingActionButton( + onPressed: () { + print( + 'ScreenUtil.getInstance().width:${ScreenUtil.getInstance().width}'); + print('ScreenUtil().width:${ScreenUtil().width}'); + }, + child: Icon(Icons.accessible_forward), + ), body: new Center( child: Column( crossAxisAlignment: CrossAxisAlignment.center, @@ -59,25 +67,25 @@ class _MyHomePageState extends State { Row( children: [ Container( - width: ScreenUtil().setWidth(375), - height: ScreenUtil().setHeight(200), + width: ScreenUtil.getInstance().setWidth(375), + height: ScreenUtil.getInstance().setHeight(200), color: Colors.red, child: Text( - '我的宽度:${ScreenUtil().setWidth(375)}dp', + '我的宽度:${ScreenUtil.getInstance().setWidth(375)}dp', style: TextStyle( color: Colors.white, - fontSize: ScreenUtil().setSp(24), + fontSize: ScreenUtil.getInstance().setSp(24), ), ), ), Container( - width: ScreenUtil().setWidth(375), - height: ScreenUtil().setHeight(200), + width: ScreenUtil.getInstance().setWidth(375), + height: ScreenUtil.getInstance().setHeight(200), color: Colors.blue, - child: Text('我的宽度:${ScreenUtil().setWidth(375)}dp', + child: Text('我的宽度:${ScreenUtil.getInstance().setWidth(375)}dp', style: TextStyle( color: Colors.white, - fontSize: ScreenUtil().setSp(24), + fontSize: ScreenUtil.getInstance().setSp(24), )), ), ], @@ -88,23 +96,23 @@ class _MyHomePageState extends State { Text('底部安全区距离:${ScreenUtil.bottomBarHeight}px'), Text('状态栏高度:${ScreenUtil.statusBarHeight}px'), Text( - '实际高度的dp与设计稿px的比例:${ScreenUtil().scaleHeight}', + '实际高度的dp与设计稿px的比例:${ScreenUtil.getInstance().scaleHeight}', textAlign: TextAlign.center, ), Text( - '实际高度的dp与设计稿px的比例:${ScreenUtil().scaleHeight}', + '实际高度的dp与设计稿px的比例:${ScreenUtil.getInstance().scaleHeight}', textAlign: TextAlign.center, ), Text( - '宽度和字体相对于设计稿放大的比例:${ScreenUtil().scaleWidth * ScreenUtil.pixelRatio}', + '宽度和字体相对于设计稿放大的比例:${ScreenUtil.getInstance().scaleWidth * ScreenUtil.pixelRatio}', textAlign: TextAlign.center, ), Text( - '高度相对于设计稿放大的比例:${ScreenUtil().scaleHeight * ScreenUtil.pixelRatio}', + '高度相对于设计稿放大的比例:${ScreenUtil.getInstance().scaleHeight * ScreenUtil.pixelRatio}', textAlign: TextAlign.center, ), SizedBox( - height: ScreenUtil().setHeight(100), + height: ScreenUtil.getInstance().setHeight(100), ), Text('系统的字体缩放比例:${ScreenUtil.textScaleFactory}'), Column( @@ -112,10 +120,12 @@ class _MyHomePageState extends State { children: [ Text('我的文字大小在设计稿上是25px,不会随着系统的文字缩放比例变化', style: TextStyle( - color: Colors.black, fontSize: ScreenUtil().setSp(24))), + color: Colors.black, fontSize: ScreenUtil.getInstance().setSp(24))), Text('我的文字大小在设计稿上是25px,会随着系统的文字缩放比例变化', style: TextStyle( - color: Colors.black, fontSize: ScreenUtil(allowFontScaling: true).setSp(24))), + color: Colors.black, + fontSize: + ScreenUtil(allowFontScaling: true).setSp(24))), ], ) ], diff --git a/example/pubspec.lock b/example/pubspec.lock index 110ce25..7dbe487 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -47,7 +47,7 @@ packages: path: ".." relative: true source: path - version: "0.4.5" + version: "0.5.0" flutter_test: dependency: "direct dev" description: flutter diff --git a/pubspec.yaml b/pubspec.yaml index e1437bf..29d61cd 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: flutter_screenutil description: A flutter plugin for adapting screen and font size.Guaranteed to look good on different models -version: 0.4.6 +version: 0.5.0 author: LiZhuoyuan homepage: https://github.com/OpenFlutter/flutter_ScreenUtil