Showing
7 changed files
with
46 additions
and
39 deletions
| 1 | -# Generated by pub on 2019-01-03 18:12:49.974343. | 1 | +# Generated by pub on 2019-01-11 11:09:46.258394. |
| 2 | async:file:///D:/flutter/.pub-cache/hosted/pub.dartlang.org/async-2.0.8/lib/ | 2 | async:file:///D:/flutter/.pub-cache/hosted/pub.dartlang.org/async-2.0.8/lib/ |
| 3 | boolean_selector:file:///D:/flutter/.pub-cache/hosted/pub.dartlang.org/boolean_selector-1.0.4/lib/ | 3 | boolean_selector:file:///D:/flutter/.pub-cache/hosted/pub.dartlang.org/boolean_selector-1.0.4/lib/ |
| 4 | charcode:file:///D:/flutter/.pub-cache/hosted/pub.dartlang.org/charcode-1.1.2/lib/ | 4 | charcode:file:///D:/flutter/.pub-cache/hosted/pub.dartlang.org/charcode-1.1.2/lib/ |
| @@ -38,8 +38,17 @@ import 'package:flutter_screenutil/flutter_screenutil.dart'; | @@ -38,8 +38,17 @@ import 'package:flutter_screenutil/flutter_screenutil.dart'; | ||
| 38 | 一定在MaterialApp的home中的页面设置(即入口文件,只需设置一次),以保证在每次使用之前设置好了适配尺寸: | 38 | 一定在MaterialApp的home中的页面设置(即入口文件,只需设置一次),以保证在每次使用之前设置好了适配尺寸: |
| 39 | 39 | ||
| 40 | ``` | 40 | ``` |
| 41 | -//设置适配尺寸 (填入设计稿中设备的屏幕尺寸) 假如设计稿是按iPhone6的尺寸设计的(iPhone6 750*1334) | ||
| 42 | - ScreenUtil.instance = ScreenUtil(width: 750, height: 1334)..init(context); | 41 | +|属性|类型|默认值|描述| |
| 42 | +|:---|:---|:---|:---| | ||
| 43 | +|width|int|1080px|设计稿中设备的宽度,单位px| | ||
| 44 | +|height|int|1920px|设计稿中设备的高度,单位px| | ||
| 45 | +|allowFontScaling|bool|false|设置字体大小是否根据系统的“字体大小”辅助选项来进行缩放| | ||
| 46 | + | ||
| 47 | + | ||
| 48 | +//设置适配尺寸 (填入设计稿中设备的屏幕尺寸) 假如设计稿是按iPhone6的尺寸设计的(iPhone6 750*1334) | ||
| 49 | +//设置字体大小是否根据系统的“字体大小”辅助选项来进行缩放 , 默认为 false | ||
| 50 | + | ||
| 51 | + ScreenUtil.instance = ScreenUtil(width: 750, height: 1334, allowFontScaling: true)..init(context); | ||
| 43 | ``` | 52 | ``` |
| 44 | 53 | ||
| 45 | ### 使用: | 54 | ### 使用: |
| @@ -78,9 +87,9 @@ Container( | @@ -78,9 +87,9 @@ Container( | ||
| 78 | 传入设计稿的px尺寸: | 87 | 传入设计稿的px尺寸: |
| 79 | 88 | ||
| 80 | ``` | 89 | ``` |
| 81 | - ScreenUtil().setSp(28) //传入字体大小,不根据系统的“字体大小”辅助选项来进行缩放 | ||
| 82 | - ScreenUtil().setSp(28,true) //传入字体大小,会根据系统的“字体大小”辅助选项来进行缩放 | ||
| 83 | - | 90 | + ScreenUtil().setSp(28) //传入字体大小,默认不根据系统的“字体大小”辅助选项来进行缩放 |
| 91 | + ScreenUtil(allowFontScaling: true).setSp(28) //传入字体大小,根据系统的“字体大小”辅助选项来进行缩放 | ||
| 92 | + | ||
| 84 | for example: | 93 | for example: |
| 85 | Text( | 94 | Text( |
| 86 | 'My font size is 28px and will not change with the system.', | 95 | 'My font size is 28px and will not change with the system.', |
| @@ -193,17 +202,16 @@ import 'package:flutter_screenutil/flutter_screenutil.dart'; | @@ -193,17 +202,16 @@ import 'package:flutter_screenutil/flutter_screenutil.dart'; | ||
| 193 | ), | 202 | ), |
| 194 | Text('系统的字体缩放比例:${ScreenUtil.textScaleFactory}'), | 203 | Text('系统的字体缩放比例:${ScreenUtil.textScaleFactory}'), |
| 195 | Column( | 204 | Column( |
| 196 | - crossAxisAlignment: CrossAxisAlignment.start, | ||
| 197 | - children: <Widget>[ | ||
| 198 | - Text('我的文字大小在设计稿上是14px,不会随着系统的文字缩放比例变化', | ||
| 199 | - style: TextStyle( | ||
| 200 | - color: Colors.black, | ||
| 201 | - fontSize: ScreenUtil().setSp(14, false))), | ||
| 202 | - Text('我的文字大小在设计稿上是14px,会随着系统的文字缩放比例变化', | ||
| 203 | - style: TextStyle( | ||
| 204 | - color: Colors.black, fontSize: ScreenUtil().setSp(14))), | ||
| 205 | - ], | ||
| 206 | - ) | 205 | + crossAxisAlignment: CrossAxisAlignment.start, |
| 206 | + children: <Widget>[ | ||
| 207 | + Text('我的文字大小在设计稿上是25px,不会随着系统的文字缩放比例变化', | ||
| 208 | + style: TextStyle( | ||
| 209 | + color: Colors.black, fontSize: ScreenUtil().setSp(24))), | ||
| 210 | + Text('我的文字大小在设计稿上是25px,会随着系统的文字缩放比例变化', | ||
| 211 | + style: TextStyle( | ||
| 212 | + color: Colors.black, fontSize: ScreenUtil(allowFontScaling: true).setSp(24))), | ||
| 213 | + ], | ||
| 214 | + ) | ||
| 207 | ], | 215 | ], |
| 208 | ), | 216 | ), |
| 209 | ), | 217 | ), |
| @@ -28,7 +28,6 @@ class MyHomePage extends StatefulWidget { | @@ -28,7 +28,6 @@ class MyHomePage extends StatefulWidget { | ||
| 28 | } | 28 | } |
| 29 | 29 | ||
| 30 | class _MyHomePageState extends State<MyHomePage> { | 30 | class _MyHomePageState extends State<MyHomePage> { |
| 31 | - | ||
| 32 | @override | 31 | @override |
| 33 | Widget build(BuildContext context) { | 32 | Widget build(BuildContext context) { |
| 34 | ///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) | 33 | ///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) |
| @@ -66,8 +65,7 @@ class _MyHomePageState extends State<MyHomePage> { | @@ -66,8 +65,7 @@ class _MyHomePageState extends State<MyHomePage> { | ||
| 66 | child: Text( | 65 | child: Text( |
| 67 | 'My width:${ScreenUtil().setWidth(375)}dp', | 66 | 'My width:${ScreenUtil().setWidth(375)}dp', |
| 68 | style: TextStyle( | 67 | style: TextStyle( |
| 69 | - color: Colors.white, | ||
| 70 | - fontSize: ScreenUtil().setSp(24, false)), | 68 | + color: Colors.white, fontSize: ScreenUtil().setSp(24)), |
| 71 | ), | 69 | ), |
| 72 | ), | 70 | ), |
| 73 | Container( | 71 | Container( |
| @@ -77,7 +75,7 @@ class _MyHomePageState extends State<MyHomePage> { | @@ -77,7 +75,7 @@ class _MyHomePageState extends State<MyHomePage> { | ||
| 77 | child: Text('My width:${ScreenUtil().setWidth(375)}dp', | 75 | child: Text('My width:${ScreenUtil().setWidth(375)}dp', |
| 78 | style: TextStyle( | 76 | style: TextStyle( |
| 79 | color: Colors.white, | 77 | color: Colors.white, |
| 80 | - fontSize: ScreenUtil().setSp(24, false))), | 78 | + fontSize: ScreenUtil().setSp(24))), |
| 81 | ), | 79 | ), |
| 82 | ], | 80 | ], |
| 83 | ), | 81 | ), |
| @@ -113,13 +111,13 @@ class _MyHomePageState extends State<MyHomePage> { | @@ -113,13 +111,13 @@ class _MyHomePageState extends State<MyHomePage> { | ||
| 113 | 'My font size is 24px on the design draft and will not change with the system.', | 111 | 'My font size is 24px on the design draft and will not change with the system.', |
| 114 | style: TextStyle( | 112 | style: TextStyle( |
| 115 | color: Colors.black, | 113 | color: Colors.black, |
| 116 | - fontSize: ScreenUtil().setSp(24, false), | 114 | + fontSize: ScreenUtil().setSp(24), |
| 117 | )), | 115 | )), |
| 118 | Text( | 116 | Text( |
| 119 | 'My font size is 24px on the design draft and will change with the system.', | 117 | 'My font size is 24px on the design draft and will change with the system.', |
| 120 | style: TextStyle( | 118 | style: TextStyle( |
| 121 | color: Colors.black, | 119 | color: Colors.black, |
| 122 | - fontSize: ScreenUtil().setSp(24), | 120 | + fontSize: ScreenUtil(allowFontScaling: true).setSp(24), |
| 123 | )), | 121 | )), |
| 124 | ], | 122 | ], |
| 125 | ) | 123 | ) |
| @@ -66,7 +66,7 @@ class _MyHomePageState extends State<MyHomePage> { | @@ -66,7 +66,7 @@ class _MyHomePageState extends State<MyHomePage> { | ||
| 66 | '我的宽度:${ScreenUtil().setWidth(375)}dp', | 66 | '我的宽度:${ScreenUtil().setWidth(375)}dp', |
| 67 | style: TextStyle( | 67 | style: TextStyle( |
| 68 | color: Colors.white, | 68 | color: Colors.white, |
| 69 | - fontSize: ScreenUtil().setSp(24, false), | 69 | + fontSize: ScreenUtil().setSp(24), |
| 70 | ), | 70 | ), |
| 71 | ), | 71 | ), |
| 72 | ), | 72 | ), |
| @@ -77,7 +77,7 @@ class _MyHomePageState extends State<MyHomePage> { | @@ -77,7 +77,7 @@ class _MyHomePageState extends State<MyHomePage> { | ||
| 77 | child: Text('我的宽度:${ScreenUtil().setWidth(375)}dp', | 77 | child: Text('我的宽度:${ScreenUtil().setWidth(375)}dp', |
| 78 | style: TextStyle( | 78 | style: TextStyle( |
| 79 | color: Colors.white, | 79 | color: Colors.white, |
| 80 | - fontSize: ScreenUtil().setSp(24, false), | 80 | + fontSize: ScreenUtil().setSp(24), |
| 81 | )), | 81 | )), |
| 82 | ), | 82 | ), |
| 83 | ], | 83 | ], |
| @@ -112,11 +112,10 @@ class _MyHomePageState extends State<MyHomePage> { | @@ -112,11 +112,10 @@ class _MyHomePageState extends State<MyHomePage> { | ||
| 112 | children: <Widget>[ | 112 | children: <Widget>[ |
| 113 | Text('我的文字大小在设计稿上是25px,不会随着系统的文字缩放比例变化', | 113 | Text('我的文字大小在设计稿上是25px,不会随着系统的文字缩放比例变化', |
| 114 | style: TextStyle( | 114 | style: TextStyle( |
| 115 | - color: Colors.black, | ||
| 116 | - fontSize: ScreenUtil().setSp(24, false))), | 115 | + color: Colors.black, fontSize: ScreenUtil().setSp(24))), |
| 117 | Text('我的文字大小在设计稿上是25px,会随着系统的文字缩放比例变化', | 116 | Text('我的文字大小在设计稿上是25px,会随着系统的文字缩放比例变化', |
| 118 | style: TextStyle( | 117 | style: TextStyle( |
| 119 | - color: Colors.black, fontSize: ScreenUtil().setSp(24))), | 118 | + color: Colors.black, fontSize: ScreenUtil(allowFontScaling: true).setSp(24))), |
| 120 | ], | 119 | ], |
| 121 | ) | 120 | ) |
| 122 | ], | 121 | ], |
| @@ -47,7 +47,7 @@ packages: | @@ -47,7 +47,7 @@ packages: | ||
| 47 | path: ".." | 47 | path: ".." |
| 48 | relative: true | 48 | relative: true |
| 49 | source: path | 49 | source: path |
| 50 | - version: "0.4.2" | 50 | + version: "0.4.5" |
| 51 | flutter_test: | 51 | flutter_test: |
| 52 | dependency: "direct dev" | 52 | dependency: "direct dev" |
| 53 | description: flutter | 53 | description: flutter |
| @@ -9,8 +9,9 @@ class ScreenUtil { | @@ -9,8 +9,9 @@ class ScreenUtil { | ||
| 9 | static ScreenUtil instance = new ScreenUtil(); | 9 | static ScreenUtil instance = new ScreenUtil(); |
| 10 | 10 | ||
| 11 | //设计稿的设备尺寸修改 | 11 | //设计稿的设备尺寸修改 |
| 12 | - int _designWidth; | ||
| 13 | - int _designHeight; | 12 | + int width; |
| 13 | + int height; | ||
| 14 | + bool allowFontScaling; | ||
| 14 | 15 | ||
| 15 | static MediaQueryData _mediaQueryData; | 16 | static MediaQueryData _mediaQueryData; |
| 16 | static double _screenWidth; | 17 | static double _screenWidth; |
| @@ -22,10 +23,11 @@ class ScreenUtil { | @@ -22,10 +23,11 @@ class ScreenUtil { | ||
| 22 | 23 | ||
| 23 | static double _textScaleFactor; | 24 | static double _textScaleFactor; |
| 24 | 25 | ||
| 25 | - ScreenUtil({int width, int height}) { | ||
| 26 | - _designWidth = width; | ||
| 27 | - _designHeight = height; | ||
| 28 | - } | 26 | + ScreenUtil({ |
| 27 | + this.width, | ||
| 28 | + this.height, | ||
| 29 | + this.allowFontScaling = false, | ||
| 30 | + }); | ||
| 29 | 31 | ||
| 30 | static ScreenUtil getInstance() { | 32 | static ScreenUtil getInstance() { |
| 31 | return instance; | 33 | return instance; |
| @@ -69,9 +71,9 @@ class ScreenUtil { | @@ -69,9 +71,9 @@ class ScreenUtil { | ||
| 69 | static double get bottomBarHeight => _bottomBarHeight * _pixelRatio; | 71 | static double get bottomBarHeight => _bottomBarHeight * _pixelRatio; |
| 70 | 72 | ||
| 71 | ///实际的dp与设计稿px的比例 | 73 | ///实际的dp与设计稿px的比例 |
| 72 | - get scaleWidth => _screenWidth / instance._designWidth; | 74 | + get scaleWidth => _screenWidth / instance.width; |
| 73 | 75 | ||
| 74 | - get scaleHeight => _screenHeight / instance._designHeight; | 76 | + get scaleHeight => _screenHeight / instance.height; |
| 75 | 77 | ||
| 76 | ///根据设计稿的设备宽度适配 | 78 | ///根据设计稿的设备宽度适配 |
| 77 | ///高度也根据这个来做适配可以保证不变形 | 79 | ///高度也根据这个来做适配可以保证不变形 |
| @@ -87,7 +89,7 @@ class ScreenUtil { | @@ -87,7 +89,7 @@ class ScreenUtil { | ||
| 87 | ///@param fontSize 传入设计稿上字体的px , | 89 | ///@param fontSize 传入设计稿上字体的px , |
| 88 | ///@param allowFontScaling 控制字体是否要根据系统的“字体大小”辅助选项来进行缩放。默认值为true。 | 90 | ///@param allowFontScaling 控制字体是否要根据系统的“字体大小”辅助选项来进行缩放。默认值为true。 |
| 89 | ///@param allowFontScaling Specifies whether fonts should scale to respect Text Size accessibility settings. The default is true. | 91 | ///@param allowFontScaling Specifies whether fonts should scale to respect Text Size accessibility settings. The default is true. |
| 90 | - setSp(int fontSize, [allowFontScaling = false]) => allowFontScaling | 92 | + setSp(int fontSize) => allowFontScaling |
| 91 | ? setWidth(fontSize) | 93 | ? setWidth(fontSize) |
| 92 | : setWidth(fontSize) / _textScaleFactor; | 94 | : setWidth(fontSize) / _textScaleFactor; |
| 93 | } | 95 | } |
| 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: 0.4.4 | 3 | +version: 0.4.5 |
| 4 | author: LiZhuoyuan <zhuoyuan93@gmail.com> | 4 | author: LiZhuoyuan <zhuoyuan93@gmail.com> |
| 5 | homepage: https://github.com/OpenFlutter/flutter_ScreenUtil | 5 | homepage: https://github.com/OpenFlutter/flutter_ScreenUtil |
| 6 | 6 |
-
Please register or login to post a comment