Showing
8 changed files
with
115 additions
and
102 deletions
1 | -# Generated by pub on 2019-01-11 11:09:46.258394. | 1 | +# Generated by pub on 2019-02-21 15:24:09.886695. |
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/ |
@@ -31,3 +31,7 @@ setSp(int fontSize, [allowFontScaling = false]) => allowFontScaling | @@ -31,3 +31,7 @@ setSp(int fontSize, [allowFontScaling = false]) => allowFontScaling | ||
31 | : setWidth(fontSize); | 31 | : setWidth(fontSize); |
32 | 32 | ||
33 | ## [0.4.4] - Fix bugs that default fonts change with the system | 33 | ## [0.4.4] - Fix bugs that default fonts change with the system |
34 | + | ||
35 | +## [0.5.0] - Fix the wrong way of using | ||
36 | + | ||
37 | +please use `ScreenUtil.getInstance()` instead of `ScreenUtil()` , for example: ScreenUtil.getInstance().setHeight(25) instead of `ScreenUtil().setHeight(25)` |
@@ -46,7 +46,7 @@ Be sure to set the page in the MaterialApp's home(ie the entry file, just set it | @@ -46,7 +46,7 @@ Be sure to set the page in the MaterialApp's home(ie the entry file, just set it | ||
46 | //fill in the screen size of the device in the design | 46 | //fill in the screen size of the device in the design |
47 | 47 | ||
48 | //default value : width : 1080px , height:1920px , allowFontScaling:false | 48 | //default value : width : 1080px , height:1920px , allowFontScaling:false |
49 | -ScreenUtil.instance = ScreenUtil()..init(context); | 49 | +ScreenUtil.instance = ScreenUtil.getInstance()..init(context); |
50 | 50 | ||
51 | //If the design is based on the size of the iPhone6 (iPhone6 750*1334) | 51 | //If the design is based on the size of the iPhone6 (iPhone6 750*1334) |
52 | ScreenUtil.instance = ScreenUtil(width: 750, height: 1334)..init(context); | 52 | ScreenUtil.instance = ScreenUtil(width: 750, height: 1334)..init(context); |
@@ -62,11 +62,9 @@ ScreenUtil.instance = ScreenUtil(width: 750, height: 1334, allowFontScaling: tru | @@ -62,11 +62,9 @@ ScreenUtil.instance = ScreenUtil(width: 750, height: 1334, allowFontScaling: tru | ||
62 | 62 | ||
63 | Pass the px size of the design draft: | 63 | Pass the px size of the design draft: |
64 | 64 | ||
65 | -Adapted to screen width: `ScreenUtil().setWidth(540)`, | 65 | +Adapted to screen width: `ScreenUtil.getInstance().setWidth(540)`, |
66 | 66 | ||
67 | -Adapted to screen height: `ScreenUtil().setHeight(200)`, | ||
68 | - | ||
69 | -You can also use `ScreenUtil.getInstance()` instead of `ScreenUtil()` , for example: `ScreenUtil.getInstance().setHeight(25)` | 67 | +Adapted to screen height: `ScreenUtil.getInstance().setHeight(200)`, |
70 | 68 | ||
71 | **Note** | 69 | **Note** |
72 | 70 | ||
@@ -78,15 +76,15 @@ setHeight method is mainly adapted in height, you want to control the height and | @@ -78,15 +76,15 @@ setHeight method is mainly adapted in height, you want to control the height and | ||
78 | //for example: | 76 | //for example: |
79 | //rectangle | 77 | //rectangle |
80 | Container( | 78 | Container( |
81 | - width: ScreenUtil().setWidth(375), | ||
82 | - height: ScreenUtil().setHeight(200), | 79 | + width: ScreenUtil.getInstance().setWidth(375), |
80 | + height: ScreenUtil.getInstance().setHeight(200), | ||
83 | ... | 81 | ... |
84 | ), | 82 | ), |
85 | 83 | ||
86 | ////If you want to display a square: | 84 | ////If you want to display a square: |
87 | Container( | 85 | Container( |
88 | - width: ScreenUtil().setWidth(300), | ||
89 | - height: ScreenUtil().setWidth(300), | 86 | + width: ScreenUtil.getInstance().setWidth(300), |
87 | + height: ScreenUtil.getInstance().setWidth(300), | ||
90 | ), | 88 | ), |
91 | 89 | ||
92 | ``` | 90 | ``` |
@@ -95,7 +93,7 @@ Container( | @@ -95,7 +93,7 @@ Container( | ||
95 | ``` | 93 | ``` |
96 | //Incoming font size,the unit is pixel, fonts will not scale to respect Text Size accessibility settings | 94 | //Incoming font size,the unit is pixel, fonts will not scale to respect Text Size accessibility settings |
97 | //(AllowallowFontScaling when initializing ScreenUtil) | 95 | //(AllowallowFontScaling when initializing ScreenUtil) |
98 | -ScreenUtil().setSp(28) | 96 | +ScreenUtil.getInstance().setSp(28) |
99 | 97 | ||
100 | //Incoming font size,the unit is pixel,fonts will scale to respect Text Size accessibility settings | 98 | //Incoming font size,the unit is pixel,fonts will scale to respect Text Size accessibility settings |
101 | //(If somewhere does not follow the global allowFontScaling setting) | 99 | //(If somewhere does not follow the global allowFontScaling setting) |
@@ -110,7 +108,7 @@ Column( | @@ -110,7 +108,7 @@ Column( | ||
110 | 'My font size is 24px on the design draft and will not change with the system.', | 108 | 'My font size is 24px on the design draft and will not change with the system.', |
111 | style: TextStyle( | 109 | style: TextStyle( |
112 | color: Colors.black, | 110 | color: Colors.black, |
113 | - fontSize: ScreenUtil().setSp(24), | 111 | + fontSize: ScreenUtil.getInstance().setSp(24), |
114 | )), | 112 | )), |
115 | Text( | 113 | Text( |
116 | 'My font size is 24px on the design draft and will change with the system.', | 114 | 'My font size is 24px on the design draft and will change with the system.', |
@@ -133,8 +131,8 @@ Column( | @@ -133,8 +131,8 @@ Column( | ||
133 | ScreenUtil.statusBarHeight //Status bar height , Notch will be higher Unit px | 131 | ScreenUtil.statusBarHeight //Status bar height , Notch will be higher Unit px |
134 | ScreenUtil.textScaleFactory //System font scaling factor | 132 | ScreenUtil.textScaleFactory //System font scaling factor |
135 | 133 | ||
136 | - ScreenUtil().scaleWidth //Ratio of actual width dp to design draft px | ||
137 | - ScreenUtil().scaleHeight //Ratio of actual height dp to design draft px | 134 | + ScreenUtil.getInstance().scaleWidth //Ratio of actual width dp to design draft px |
135 | + ScreenUtil.getInstance().scaleHeight //Ratio of actual height dp to design draft px | ||
138 | 136 | ||
139 | ``` | 137 | ``` |
140 | 138 | ||
@@ -157,13 +155,13 @@ import 'package:flutter_screenutil/flutter_screenutil.dart'; | @@ -157,13 +155,13 @@ import 'package:flutter_screenutil/flutter_screenutil.dart'; | ||
157 | print( | 155 | print( |
158 | 'Status bar height:${ScreenUtil.statusBarHeight}px'); //Status bar height , Notch will be higher Unit px | 156 | 'Status bar height:${ScreenUtil.statusBarHeight}px'); //Status bar height , Notch will be higher Unit px |
159 | print( | 157 | print( |
160 | - 'Ratio of actual width dp to design draft px:${ScreenUtil().scaleWidth}'); | 158 | + 'Ratio of actual width dp to design draft px:${ScreenUtil.getInstance().scaleWidth}'); |
161 | print( | 159 | print( |
162 | - 'Ratio of actual height dp to design draft px:${ScreenUtil().scaleHeight}'); | 160 | + 'Ratio of actual height dp to design draft px:${ScreenUtil.getInstance().scaleHeight}'); |
163 | print( | 161 | print( |
164 | - 'The ratio of font and width to the size of the design:${ScreenUtil().scaleWidth * ScreenUtil.pixelRatio}'); | 162 | + 'The ratio of font and width to the size of the design:${ScreenUtil.getInstance().scaleWidth * ScreenUtil.pixelRatio}'); |
165 | print( | 163 | print( |
166 | - 'The ratio of height width to the size of the design:${ScreenUtil().scaleHeight * ScreenUtil.pixelRatio}'); | 164 | + 'The ratio of height width to the size of the design:${ScreenUtil.getInstance().scaleHeight * ScreenUtil.pixelRatio}'); |
167 | return new Scaffold( | 165 | return new Scaffold( |
168 | appBar: new AppBar( | 166 | appBar: new AppBar( |
169 | title: new Text(widget.title), | 167 | title: new Text(widget.title), |
@@ -175,24 +173,24 @@ import 'package:flutter_screenutil/flutter_screenutil.dart'; | @@ -175,24 +173,24 @@ import 'package:flutter_screenutil/flutter_screenutil.dart'; | ||
175 | Row( | 173 | Row( |
176 | children: <Widget>[ | 174 | children: <Widget>[ |
177 | Container( | 175 | Container( |
178 | - width: ScreenUtil().setWidth(375), | ||
179 | - height: ScreenUtil().setHeight(200), | 176 | + width: ScreenUtil.getInstance().setWidth(375), |
177 | + height: ScreenUtil.getInstance().setHeight(200), | ||
180 | color: Colors.red, | 178 | color: Colors.red, |
181 | child: Text( | 179 | child: Text( |
182 | - 'My width:${ScreenUtil().setWidth(375)}dp', | 180 | + 'My width:${ScreenUtil.getInstance().setWidth(375)}dp', |
183 | style: TextStyle( | 181 | style: TextStyle( |
184 | color: Colors.white, | 182 | color: Colors.white, |
185 | - fontSize: ScreenUtil().setSp(12)), | 183 | + fontSize: ScreenUtil.getInstance().setSp(12)), |
186 | ), | 184 | ), |
187 | ), | 185 | ), |
188 | Container( | 186 | Container( |
189 | - width: ScreenUtil().setWidth(375), | ||
190 | - height: ScreenUtil().setHeight(200), | 187 | + width: ScreenUtil.getInstance().setWidth(375), |
188 | + height: ScreenUtil.getInstance().setHeight(200), | ||
191 | color: Colors.blue, | 189 | color: Colors.blue, |
192 | - child: Text('My width:${ScreenUtil().setWidth(375)}dp', | 190 | + child: Text('My width:${ScreenUtil.getInstance().setWidth(375)}dp', |
193 | style: TextStyle( | 191 | style: TextStyle( |
194 | color: Colors.white, | 192 | color: Colors.white, |
195 | - fontSize: ScreenUtil().setSp(12))), | 193 | + fontSize: ScreenUtil.getInstance().setSp(12))), |
196 | ), | 194 | ), |
197 | ], | 195 | ], |
198 | ), | 196 | ), |
@@ -202,23 +200,23 @@ import 'package:flutter_screenutil/flutter_screenutil.dart'; | @@ -202,23 +200,23 @@ import 'package:flutter_screenutil/flutter_screenutil.dart'; | ||
202 | Text('Bottom safe zone distance:${ScreenUtil.bottomBarHeight}px'), | 200 | Text('Bottom safe zone distance:${ScreenUtil.bottomBarHeight}px'), |
203 | Text('Status bar height:${ScreenUtil.statusBarHeight}px'), | 201 | Text('Status bar height:${ScreenUtil.statusBarHeight}px'), |
204 | Text( | 202 | Text( |
205 | - 'Ratio of actual width dp to design draft px:${ScreenUtil().scaleWidth}', | 203 | + 'Ratio of actual width dp to design draft px:${ScreenUtil.getInstance().scaleWidth}', |
206 | textAlign: TextAlign.center, | 204 | textAlign: TextAlign.center, |
207 | ), | 205 | ), |
208 | Text( | 206 | Text( |
209 | - 'Ratio of actual height dp to design draft px:${ScreenUtil().scaleHeight}', | 207 | + 'Ratio of actual height dp to design draft px:${ScreenUtil.getInstance().scaleHeight}', |
210 | textAlign: TextAlign.center, | 208 | textAlign: TextAlign.center, |
211 | ), | 209 | ), |
212 | Text( | 210 | Text( |
213 | - 'The ratio of font and width to the size of the design:${ScreenUtil().scaleWidth * ScreenUtil.pixelRatio}', | 211 | + 'The ratio of font and width to the size of the design:${ScreenUtil.getInstance().scaleWidth * ScreenUtil.pixelRatio}', |
214 | textAlign: TextAlign.center, | 212 | textAlign: TextAlign.center, |
215 | ), | 213 | ), |
216 | Text( | 214 | Text( |
217 | - 'The ratio of height width to the size of the design:${ScreenUtil().scaleHeight * ScreenUtil.pixelRatio}', | 215 | + 'The ratio of height width to the size of the design:${ScreenUtil.getInstance().scaleHeight * ScreenUtil.pixelRatio}', |
218 | textAlign: TextAlign.center, | 216 | textAlign: TextAlign.center, |
219 | ), | 217 | ), |
220 | SizedBox( | 218 | SizedBox( |
221 | - height: ScreenUtil().setHeight(100), | 219 | + height: ScreenUtil.getInstance().setHeight(100), |
222 | ), | 220 | ), |
223 | Text('System font scaling factor:${ScreenUtil.textScaleFactory}'), | 221 | Text('System font scaling factor:${ScreenUtil.textScaleFactory}'), |
224 | Column( | 222 | Column( |
@@ -228,7 +226,7 @@ import 'package:flutter_screenutil/flutter_screenutil.dart'; | @@ -228,7 +226,7 @@ import 'package:flutter_screenutil/flutter_screenutil.dart'; | ||
228 | 'My font size is 14px on the design draft and will not change with the system.', | 226 | 'My font size is 14px on the design draft and will not change with the system.', |
229 | style: TextStyle( | 227 | style: TextStyle( |
230 | color: Colors.black, | 228 | color: Colors.black, |
231 | - fontSize: ScreenUtil().setSp(14), | 229 | + fontSize: ScreenUtil.getInstance().setSp(14), |
232 | )), | 230 | )), |
233 | Text( | 231 | Text( |
234 | 'My font size is 14px on the design draft and will change with the system.', | 232 | 'My font size is 14px on the design draft and will change with the system.', |
@@ -26,7 +26,7 @@ dependencies: | @@ -26,7 +26,7 @@ dependencies: | ||
26 | flutter: | 26 | flutter: |
27 | sdk: flutter | 27 | sdk: flutter |
28 | # 添加依赖 | 28 | # 添加依赖 |
29 | - flutter_screenutil: ^0.4.2 | 29 | + flutter_screenutil: ^0.5.0 |
30 | ``` | 30 | ``` |
31 | 31 | ||
32 | ### 在每个使用的地方导入包: | 32 | ### 在每个使用的地方导入包: |
@@ -50,7 +50,7 @@ import 'package:flutter_screenutil/flutter_screenutil.dart'; | @@ -50,7 +50,7 @@ import 'package:flutter_screenutil/flutter_screenutil.dart'; | ||
50 | //填入设计稿中设备的屏幕尺寸 | 50 | //填入设计稿中设备的屏幕尺寸 |
51 | 51 | ||
52 | //默认 width : 1080px , height:1920px , allowFontScaling:false | 52 | //默认 width : 1080px , height:1920px , allowFontScaling:false |
53 | -ScreenUtil.instance = ScreenUtil()..init(context); | 53 | +ScreenUtil.instance = ScreenUtil.getInstance()..init(context); |
54 | 54 | ||
55 | //假如设计稿是按iPhone6的尺寸设计的(iPhone6 750*1334) | 55 | //假如设计稿是按iPhone6的尺寸设计的(iPhone6 750*1334) |
56 | ScreenUtil.instance = ScreenUtil(width: 750, height: 1334)..init(context); | 56 | ScreenUtil.instance = ScreenUtil(width: 750, height: 1334)..init(context); |
@@ -66,11 +66,10 @@ ScreenUtil.instance = ScreenUtil(width: 750, height: 1334, allowFontScaling: tru | @@ -66,11 +66,10 @@ ScreenUtil.instance = ScreenUtil(width: 750, height: 1334, allowFontScaling: tru | ||
66 | 66 | ||
67 | 传入设计稿的px尺寸: | 67 | 传入设计稿的px尺寸: |
68 | 68 | ||
69 | -根据屏幕宽度适配 `width: ScreenUtil().setWidth(540)`, | 69 | +根据屏幕宽度适配 `width: ScreenUtil.getInstance().setWidth(540)`, |
70 | 70 | ||
71 | -根据屏幕高度适配 `height: ScreenUtil().setHeight(200)`, | 71 | +根据屏幕高度适配 `height: ScreenUtil.getInstance().setHeight(200)`, |
72 | 72 | ||
73 | -也可以使用 `ScreenUtil.getInstance()` 来替代`ScreenUtil()` , 例如:`ScreenUtil.getInstance().setHeight(25)` | ||
74 | 73 | ||
75 | **注意** | 74 | **注意** |
76 | 75 | ||
@@ -83,14 +82,14 @@ setHeight瘜蜓閬擃漲銝, 雿UI銝撅 | @@ -83,14 +82,14 @@ setHeight瘜蜓閬擃漲銝, 雿UI銝撅 | ||
83 | ``` | 82 | ``` |
84 | //长方形: | 83 | //长方形: |
85 | Container( | 84 | Container( |
86 | - width: ScreenUtil().setWidth(375), | ||
87 | - height: ScreenUtil().setHeight(200), | 85 | + width: ScreenUtil.getInstance().setWidth(375), |
86 | + height: ScreenUtil.getInstance().setHeight(200), | ||
88 | ), | 87 | ), |
89 | 88 | ||
90 | //如果你想显示一个正方形: | 89 | //如果你想显示一个正方形: |
91 | Container( | 90 | Container( |
92 | - width: ScreenUtil().setWidth(300), | ||
93 | - height: ScreenUtil().setWidth(300), | 91 | + width: ScreenUtil.getInstance().setWidth(300), |
92 | + height: ScreenUtil.getInstance().setWidth(300), | ||
94 | ), | 93 | ), |
95 | ``` | 94 | ``` |
96 | 95 | ||
@@ -99,7 +98,7 @@ Container( | @@ -99,7 +98,7 @@ Container( | ||
99 | 98 | ||
100 | ``` | 99 | ``` |
101 | //传入字体大小,默认不根据系统的“字体大小”辅助选项来进行缩放(可在初始化ScreenUtil时设置allowFontScaling) | 100 | //传入字体大小,默认不根据系统的“字体大小”辅助选项来进行缩放(可在初始化ScreenUtil时设置allowFontScaling) |
102 | -ScreenUtil().setSp(28) | 101 | +ScreenUtil.getInstance().setSp(28) |
103 | 102 | ||
104 | //传入字体大小,根据系统的“字体大小”辅助选项来进行缩放(如果某个地方不遵循全局的allowFontScaling设置) | 103 | //传入字体大小,根据系统的“字体大小”辅助选项来进行缩放(如果某个地方不遵循全局的allowFontScaling设置) |
105 | ScreenUtil(allowFontScaling: true).setSp(28) | 104 | ScreenUtil(allowFontScaling: true).setSp(28) |
@@ -111,7 +110,7 @@ Column( | @@ -111,7 +110,7 @@ Column( | ||
111 | children: <Widget>[ | 110 | children: <Widget>[ |
112 | Text('我的文字大小在设计稿上是25px,不会随着系统的文字缩放比例变化', | 111 | Text('我的文字大小在设计稿上是25px,不会随着系统的文字缩放比例变化', |
113 | style: TextStyle( | 112 | style: TextStyle( |
114 | - color: Colors.black, fontSize: ScreenUtil().setSp(24))), | 113 | + color: Colors.black, fontSize: ScreenUtil.getInstance().setSp(24))), |
115 | Text('我的文字大小在设计稿上是25px,会随着系统的文字缩放比例变化', | 114 | Text('我的文字大小在设计稿上是25px,会随着系统的文字缩放比例变化', |
116 | style: TextStyle( | 115 | style: TextStyle( |
117 | color: Colors.black, fontSize: ScreenUtil(allowFontScaling: true).setSp(24))), | 116 | color: Colors.black, fontSize: ScreenUtil(allowFontScaling: true).setSp(24))), |
@@ -130,8 +129,8 @@ Column( | @@ -130,8 +129,8 @@ Column( | ||
130 | ScreenUtil.statusBarHeight //状态栏高度 刘海屏会更高 单位px | 129 | ScreenUtil.statusBarHeight //状态栏高度 刘海屏会更高 单位px |
131 | ScreenUtil.textScaleFactory //系统字体缩放比例 | 130 | ScreenUtil.textScaleFactory //系统字体缩放比例 |
132 | 131 | ||
133 | - ScreenUtil().scaleWidth // 实际宽度的dp与设计稿px的比例 | ||
134 | - ScreenUtil().scaleHeight // 实际高度的dp与设计稿px的比例 | 132 | + ScreenUtil.getInstance().scaleWidth // 实际宽度的dp与设计稿px的比例 |
133 | + ScreenUtil.getInstance().scaleHeight // 实际高度的dp与设计稿px的比例 | ||
135 | 134 | ||
136 | ``` | 135 | ``` |
137 | 136 | ||
@@ -153,13 +152,13 @@ import 'package:flutter_screenutil/flutter_screenutil.dart'; | @@ -153,13 +152,13 @@ import 'package:flutter_screenutil/flutter_screenutil.dart'; | ||
153 | print( | 152 | print( |
154 | '状态栏高度:${ScreenUtil.statusBarHeight}px'); //Status bar height , Notch will be higher Unit px | 153 | '状态栏高度:${ScreenUtil.statusBarHeight}px'); //Status bar height , Notch will be higher Unit px |
155 | 154 | ||
156 | - print('实际宽度的dp与设计稿px的比例:${ScreenUtil().scaleWidth}'); | ||
157 | - print('实际高度的dp与设计稿px的比例:${ScreenUtil().scaleHeight}'); | 155 | + print('实际宽度的dp与设计稿px的比例:${ScreenUtil.getInstance().scaleWidth}'); |
156 | + print('实际高度的dp与设计稿px的比例:${ScreenUtil.getInstance().scaleHeight}'); | ||
158 | 157 | ||
159 | print( | 158 | print( |
160 | - '宽度和字体相对于设计稿放大的比例:${ScreenUtil().scaleWidth * ScreenUtil.pixelRatio}'); | 159 | + '宽度和字体相对于设计稿放大的比例:${ScreenUtil.getInstance().scaleWidth * ScreenUtil.pixelRatio}'); |
161 | print( | 160 | print( |
162 | - '高度相对于设计稿放大的比例:${ScreenUtil().scaleHeight * ScreenUtil.pixelRatio}'); | 161 | + '高度相对于设计稿放大的比例:${ScreenUtil.getInstance().scaleHeight * ScreenUtil.pixelRatio}'); |
163 | print('系统的字体缩放比例:${ScreenUtil.textScaleFactory}'); | 162 | print('系统的字体缩放比例:${ScreenUtil.textScaleFactory}'); |
164 | 163 | ||
165 | return new Scaffold( | 164 | return new Scaffold( |
@@ -173,25 +172,25 @@ import 'package:flutter_screenutil/flutter_screenutil.dart'; | @@ -173,25 +172,25 @@ import 'package:flutter_screenutil/flutter_screenutil.dart'; | ||
173 | Row( | 172 | Row( |
174 | children: <Widget>[ | 173 | children: <Widget>[ |
175 | Container( | 174 | Container( |
176 | - width: ScreenUtil().setWidth(375), | ||
177 | - height: ScreenUtil().setHeight(200), | 175 | + width: ScreenUtil.getInstance().setWidth(375), |
176 | + height: ScreenUtil.getInstance().setHeight(200), | ||
178 | color: Colors.red, | 177 | color: Colors.red, |
179 | child: Text( | 178 | child: Text( |
180 | - '我的宽度:${ScreenUtil().setWidth(375)}dp', | 179 | + '我的宽度:${ScreenUtil.getInstance().setWidth(375)}dp', |
181 | style: TextStyle( | 180 | style: TextStyle( |
182 | color: Colors.white, | 181 | color: Colors.white, |
183 | - fontSize: ScreenUtil().setSp(12), | 182 | + fontSize: ScreenUtil.getInstance().setSp(12), |
184 | ), | 183 | ), |
185 | ), | 184 | ), |
186 | ), | 185 | ), |
187 | Container( | 186 | Container( |
188 | - width: ScreenUtil().setWidth(375), | ||
189 | - height: ScreenUtil().setHeight(200), | 187 | + width: ScreenUtil.getInstance().setWidth(375), |
188 | + height: ScreenUtil.getInstance().setHeight(200), | ||
190 | color: Colors.blue, | 189 | color: Colors.blue, |
191 | - child: Text('我的宽度:${ScreenUtil().setWidth(375)}dp', | 190 | + child: Text('我的宽度:${ScreenUtil.getInstance().setWidth(375)}dp', |
192 | style: TextStyle( | 191 | style: TextStyle( |
193 | color: Colors.white, | 192 | color: Colors.white, |
194 | - fontSize: ScreenUtil().setSp(12), | 193 | + fontSize: ScreenUtil.getInstance().setSp(12), |
195 | )), | 194 | )), |
196 | ), | 195 | ), |
197 | ], | 196 | ], |
@@ -202,23 +201,23 @@ import 'package:flutter_screenutil/flutter_screenutil.dart'; | @@ -202,23 +201,23 @@ import 'package:flutter_screenutil/flutter_screenutil.dart'; | ||
202 | Text('底部安全区距离:${ScreenUtil.bottomBarHeight}px'), | 201 | Text('底部安全区距离:${ScreenUtil.bottomBarHeight}px'), |
203 | Text('状态栏高度:${ScreenUtil.statusBarHeight}px'), | 202 | Text('状态栏高度:${ScreenUtil.statusBarHeight}px'), |
204 | Text( | 203 | Text( |
205 | - '实际高度的dp与设计稿px的比例:${ScreenUtil().scaleHeight}', | 204 | + '实际高度的dp与设计稿px的比例:${ScreenUtil.getInstance().scaleHeight}', |
206 | textAlign: TextAlign.center, | 205 | textAlign: TextAlign.center, |
207 | ), | 206 | ), |
208 | Text( | 207 | Text( |
209 | - '实际高度的dp与设计稿px的比例:${ScreenUtil().scaleHeight}', | 208 | + '实际高度的dp与设计稿px的比例:${ScreenUtil.getInstance().scaleHeight}', |
210 | textAlign: TextAlign.center, | 209 | textAlign: TextAlign.center, |
211 | ), | 210 | ), |
212 | Text( | 211 | Text( |
213 | - '宽度和字体相对于设计稿放大的比例:${ScreenUtil().scaleWidth * ScreenUtil.pixelRatio}', | 212 | + '宽度和字体相对于设计稿放大的比例:${ScreenUtil.getInstance().scaleWidth * ScreenUtil.pixelRatio}', |
214 | textAlign: TextAlign.center, | 213 | textAlign: TextAlign.center, |
215 | ), | 214 | ), |
216 | Text( | 215 | Text( |
217 | - '高度相对于设计稿放大的比例:${ScreenUtil().scaleHeight * ScreenUtil.pixelRatio}', | 216 | + '高度相对于设计稿放大的比例:${ScreenUtil.getInstance().scaleHeight * ScreenUtil.pixelRatio}', |
218 | textAlign: TextAlign.center, | 217 | textAlign: TextAlign.center, |
219 | ), | 218 | ), |
220 | SizedBox( | 219 | SizedBox( |
221 | - height: ScreenUtil().setHeight(100), | 220 | + height: ScreenUtil.getInstance().setHeight(100), |
222 | ), | 221 | ), |
223 | Text('系统的字体缩放比例:${ScreenUtil.textScaleFactory}'), | 222 | Text('系统的字体缩放比例:${ScreenUtil.textScaleFactory}'), |
224 | Column( | 223 | Column( |
@@ -226,7 +225,7 @@ import 'package:flutter_screenutil/flutter_screenutil.dart'; | @@ -226,7 +225,7 @@ import 'package:flutter_screenutil/flutter_screenutil.dart'; | ||
226 | children: <Widget>[ | 225 | children: <Widget>[ |
227 | Text('我的文字大小在设计稿上是25px,不会随着系统的文字缩放比例变化', | 226 | Text('我的文字大小在设计稿上是25px,不会随着系统的文字缩放比例变化', |
228 | style: TextStyle( | 227 | style: TextStyle( |
229 | - color: Colors.black, fontSize: ScreenUtil().setSp(24))), | 228 | + color: Colors.black, fontSize: ScreenUtil.getInstance().setSp(24))), |
230 | Text('我的文字大小在设计稿上是25px,会随着系统的文字缩放比例变化', | 229 | Text('我的文字大小在设计稿上是25px,会随着系统的文字缩放比例变化', |
231 | style: TextStyle( | 230 | style: TextStyle( |
232 | color: Colors.black, fontSize: ScreenUtil(allowFontScaling: true).setSp(24))), | 231 | color: Colors.black, fontSize: ScreenUtil(allowFontScaling: true).setSp(24))), |
@@ -42,13 +42,13 @@ class _MyHomePageState extends State<MyHomePage> { | @@ -42,13 +42,13 @@ class _MyHomePageState extends State<MyHomePage> { | ||
42 | print( | 42 | print( |
43 | 'Status bar height:${ScreenUtil.statusBarHeight}px'); //Status bar height , Notch will be higher Unit px | 43 | 'Status bar height:${ScreenUtil.statusBarHeight}px'); //Status bar height , Notch will be higher Unit px |
44 | print( | 44 | print( |
45 | - 'Ratio of actual width dp to design draft px:${ScreenUtil().scaleWidth}'); | 45 | + 'Ratio of actual width dp to design draft px:${ScreenUtil.getInstance().scaleWidth}'); |
46 | print( | 46 | print( |
47 | - 'Ratio of actual height dp to design draft px:${ScreenUtil().scaleHeight}'); | 47 | + 'Ratio of actual height dp to design draft px:${ScreenUtil.getInstance().scaleHeight}'); |
48 | print( | 48 | print( |
49 | - 'The ratio of font and width to the size of the design:${ScreenUtil().scaleWidth * ScreenUtil.pixelRatio}'); | 49 | + 'The ratio of font and width to the size of the design:${ScreenUtil.getInstance().scaleWidth * ScreenUtil.pixelRatio}'); |
50 | print( | 50 | print( |
51 | - 'The ratio of height width to the size of the design:${ScreenUtil().scaleHeight * ScreenUtil.pixelRatio}'); | 51 | + 'The ratio of height width to the size of the design:${ScreenUtil.getInstance().scaleHeight * ScreenUtil.pixelRatio}'); |
52 | return new Scaffold( | 52 | return new Scaffold( |
53 | appBar: new AppBar( | 53 | appBar: new AppBar( |
54 | title: new Text(widget.title), | 54 | title: new Text(widget.title), |
@@ -60,23 +60,25 @@ class _MyHomePageState extends State<MyHomePage> { | @@ -60,23 +60,25 @@ class _MyHomePageState extends State<MyHomePage> { | ||
60 | Row( | 60 | Row( |
61 | children: <Widget>[ | 61 | children: <Widget>[ |
62 | Container( | 62 | Container( |
63 | - width: ScreenUtil().setWidth(375), | ||
64 | - height: ScreenUtil().setHeight(200), | 63 | + width: ScreenUtil.getInstance().setWidth(375), |
64 | + height: ScreenUtil.getInstance().setHeight(200), | ||
65 | color: Colors.red, | 65 | color: Colors.red, |
66 | child: Text( | 66 | child: Text( |
67 | - 'My width:${ScreenUtil().setWidth(375)}dp', | 67 | + 'My width:${ScreenUtil.getInstance().setWidth(375)}dp', |
68 | style: TextStyle( | 68 | style: TextStyle( |
69 | - color: Colors.white, fontSize: ScreenUtil().setSp(24)), | 69 | + color: Colors.white, |
70 | + fontSize: ScreenUtil.getInstance().setSp(24)), | ||
70 | ), | 71 | ), |
71 | ), | 72 | ), |
72 | Container( | 73 | Container( |
73 | - width: ScreenUtil().setWidth(375), | ||
74 | - height: ScreenUtil().setHeight(200), | 74 | + width: ScreenUtil.getInstance().setWidth(375), |
75 | + height: ScreenUtil.getInstance().setHeight(200), | ||
75 | color: Colors.blue, | 76 | color: Colors.blue, |
76 | - child: Text('My width:${ScreenUtil().setWidth(375)}dp', | 77 | + child: Text( |
78 | + 'My width:${ScreenUtil.getInstance().setWidth(375)}dp', | ||
77 | style: TextStyle( | 79 | style: TextStyle( |
78 | color: Colors.white, | 80 | color: Colors.white, |
79 | - fontSize: ScreenUtil().setSp(24))), | 81 | + fontSize: ScreenUtil.getInstance().setSp(24))), |
80 | ), | 82 | ), |
81 | ], | 83 | ], |
82 | ), | 84 | ), |
@@ -86,23 +88,23 @@ class _MyHomePageState extends State<MyHomePage> { | @@ -86,23 +88,23 @@ class _MyHomePageState extends State<MyHomePage> { | ||
86 | Text('Bottom safe zone distance:${ScreenUtil.bottomBarHeight}px'), | 88 | Text('Bottom safe zone distance:${ScreenUtil.bottomBarHeight}px'), |
87 | Text('Status bar height:${ScreenUtil.statusBarHeight}px'), | 89 | Text('Status bar height:${ScreenUtil.statusBarHeight}px'), |
88 | Text( | 90 | Text( |
89 | - 'Ratio of actual width dp to design draft px:${ScreenUtil().scaleWidth}', | 91 | + 'Ratio of actual width dp to design draft px:${ScreenUtil.getInstance().scaleWidth}', |
90 | textAlign: TextAlign.center, | 92 | textAlign: TextAlign.center, |
91 | ), | 93 | ), |
92 | Text( | 94 | Text( |
93 | - 'Ratio of actual height dp to design draft px:${ScreenUtil().scaleHeight}', | 95 | + 'Ratio of actual height dp to design draft px:${ScreenUtil.getInstance().scaleHeight}', |
94 | textAlign: TextAlign.center, | 96 | textAlign: TextAlign.center, |
95 | ), | 97 | ), |
96 | Text( | 98 | Text( |
97 | - 'The ratio of font and width to the size of the design:${ScreenUtil().scaleWidth * ScreenUtil.pixelRatio}', | 99 | + 'The ratio of font and width to the size of the design:${ScreenUtil.getInstance().scaleWidth * ScreenUtil.pixelRatio}', |
98 | textAlign: TextAlign.center, | 100 | textAlign: TextAlign.center, |
99 | ), | 101 | ), |
100 | Text( | 102 | Text( |
101 | - 'The ratio of height width to the size of the design:${ScreenUtil().scaleHeight * ScreenUtil.pixelRatio}', | 103 | + 'The ratio of height width to the size of the design:${ScreenUtil.getInstance().scaleHeight * ScreenUtil.pixelRatio}', |
102 | textAlign: TextAlign.center, | 104 | textAlign: TextAlign.center, |
103 | ), | 105 | ), |
104 | SizedBox( | 106 | SizedBox( |
105 | - height: ScreenUtil().setHeight(100), | 107 | + height: ScreenUtil.getInstance().setHeight(100), |
106 | ), | 108 | ), |
107 | Text('System font scaling factor:${ScreenUtil.textScaleFactory}'), | 109 | Text('System font scaling factor:${ScreenUtil.textScaleFactory}'), |
108 | Column( | 110 | Column( |
@@ -112,7 +114,7 @@ class _MyHomePageState extends State<MyHomePage> { | @@ -112,7 +114,7 @@ class _MyHomePageState extends State<MyHomePage> { | ||
112 | 'My font size is 24px on the design draft and will not change with the system.', | 114 | 'My font size is 24px on the design draft and will not change with the system.', |
113 | style: TextStyle( | 115 | style: TextStyle( |
114 | color: Colors.black, | 116 | color: Colors.black, |
115 | - fontSize: ScreenUtil().setSp(24), | 117 | + fontSize: ScreenUtil.getInstance().setSp(24), |
116 | )), | 118 | )), |
117 | Text( | 119 | Text( |
118 | 'My font size is 24px on the design draft and will change with the system.', | 120 | 'My font size is 24px on the design draft and will change with the system.', |
@@ -40,18 +40,26 @@ class _MyHomePageState extends State<MyHomePage> { | @@ -40,18 +40,26 @@ class _MyHomePageState extends State<MyHomePage> { | ||
40 | print( | 40 | print( |
41 | '状态栏高度:${ScreenUtil.statusBarHeight}px'); //Status bar height , Notch will be higher Unit px | 41 | '状态栏高度:${ScreenUtil.statusBarHeight}px'); //Status bar height , Notch will be higher Unit px |
42 | 42 | ||
43 | - print('实际宽度的dp与设计稿px的比例:${ScreenUtil().scaleWidth}'); | ||
44 | - print('实际高度的dp与设计稿px的比例:${ScreenUtil().scaleHeight}'); | 43 | + print('实际宽度的dp与设计稿px的比例:${ScreenUtil.getInstance().scaleWidth}'); |
44 | + print('实际高度的dp与设计稿px的比例:${ScreenUtil.getInstance().scaleHeight}'); | ||
45 | 45 | ||
46 | print( | 46 | print( |
47 | - '宽度和字体相对于设计稿放大的比例:${ScreenUtil().scaleWidth * ScreenUtil.pixelRatio}'); | ||
48 | - print('高度相对于设计稿放大的比例:${ScreenUtil().scaleHeight * ScreenUtil.pixelRatio}'); | 47 | + '宽度和字体相对于设计稿放大的比例:${ScreenUtil.getInstance().scaleWidth * ScreenUtil.pixelRatio}'); |
48 | + print('高度相对于设计稿放大的比例:${ScreenUtil.getInstance().scaleHeight * ScreenUtil.pixelRatio}'); | ||
49 | print('系统的字体缩放比例:${ScreenUtil.textScaleFactory}'); | 49 | print('系统的字体缩放比例:${ScreenUtil.textScaleFactory}'); |
50 | 50 | ||
51 | return new Scaffold( | 51 | return new Scaffold( |
52 | appBar: new AppBar( | 52 | appBar: new AppBar( |
53 | title: new Text(widget.title), | 53 | title: new Text(widget.title), |
54 | ), | 54 | ), |
55 | + floatingActionButton: FloatingActionButton( | ||
56 | + onPressed: () { | ||
57 | + print( | ||
58 | + 'ScreenUtil.getInstance().width:${ScreenUtil.getInstance().width}'); | ||
59 | + print('ScreenUtil().width:${ScreenUtil().width}'); | ||
60 | + }, | ||
61 | + child: Icon(Icons.accessible_forward), | ||
62 | + ), | ||
55 | body: new Center( | 63 | body: new Center( |
56 | child: Column( | 64 | child: Column( |
57 | crossAxisAlignment: CrossAxisAlignment.center, | 65 | crossAxisAlignment: CrossAxisAlignment.center, |
@@ -59,25 +67,25 @@ class _MyHomePageState extends State<MyHomePage> { | @@ -59,25 +67,25 @@ class _MyHomePageState extends State<MyHomePage> { | ||
59 | Row( | 67 | Row( |
60 | children: <Widget>[ | 68 | children: <Widget>[ |
61 | Container( | 69 | Container( |
62 | - width: ScreenUtil().setWidth(375), | ||
63 | - height: ScreenUtil().setHeight(200), | 70 | + width: ScreenUtil.getInstance().setWidth(375), |
71 | + height: ScreenUtil.getInstance().setHeight(200), | ||
64 | color: Colors.red, | 72 | color: Colors.red, |
65 | child: Text( | 73 | child: Text( |
66 | - '我的宽度:${ScreenUtil().setWidth(375)}dp', | 74 | + '我的宽度:${ScreenUtil.getInstance().setWidth(375)}dp', |
67 | style: TextStyle( | 75 | style: TextStyle( |
68 | color: Colors.white, | 76 | color: Colors.white, |
69 | - fontSize: ScreenUtil().setSp(24), | 77 | + fontSize: ScreenUtil.getInstance().setSp(24), |
70 | ), | 78 | ), |
71 | ), | 79 | ), |
72 | ), | 80 | ), |
73 | Container( | 81 | Container( |
74 | - width: ScreenUtil().setWidth(375), | ||
75 | - height: ScreenUtil().setHeight(200), | 82 | + width: ScreenUtil.getInstance().setWidth(375), |
83 | + height: ScreenUtil.getInstance().setHeight(200), | ||
76 | color: Colors.blue, | 84 | color: Colors.blue, |
77 | - child: Text('我的宽度:${ScreenUtil().setWidth(375)}dp', | 85 | + child: Text('我的宽度:${ScreenUtil.getInstance().setWidth(375)}dp', |
78 | style: TextStyle( | 86 | style: TextStyle( |
79 | color: Colors.white, | 87 | color: Colors.white, |
80 | - fontSize: ScreenUtil().setSp(24), | 88 | + fontSize: ScreenUtil.getInstance().setSp(24), |
81 | )), | 89 | )), |
82 | ), | 90 | ), |
83 | ], | 91 | ], |
@@ -88,23 +96,23 @@ class _MyHomePageState extends State<MyHomePage> { | @@ -88,23 +96,23 @@ class _MyHomePageState extends State<MyHomePage> { | ||
88 | Text('底部安全区距离:${ScreenUtil.bottomBarHeight}px'), | 96 | Text('底部安全区距离:${ScreenUtil.bottomBarHeight}px'), |
89 | Text('状态栏高度:${ScreenUtil.statusBarHeight}px'), | 97 | Text('状态栏高度:${ScreenUtil.statusBarHeight}px'), |
90 | Text( | 98 | Text( |
91 | - '实际高度的dp与设计稿px的比例:${ScreenUtil().scaleHeight}', | 99 | + '实际高度的dp与设计稿px的比例:${ScreenUtil.getInstance().scaleHeight}', |
92 | textAlign: TextAlign.center, | 100 | textAlign: TextAlign.center, |
93 | ), | 101 | ), |
94 | Text( | 102 | Text( |
95 | - '实际高度的dp与设计稿px的比例:${ScreenUtil().scaleHeight}', | 103 | + '实际高度的dp与设计稿px的比例:${ScreenUtil.getInstance().scaleHeight}', |
96 | textAlign: TextAlign.center, | 104 | textAlign: TextAlign.center, |
97 | ), | 105 | ), |
98 | Text( | 106 | Text( |
99 | - '宽度和字体相对于设计稿放大的比例:${ScreenUtil().scaleWidth * ScreenUtil.pixelRatio}', | 107 | + '宽度和字体相对于设计稿放大的比例:${ScreenUtil.getInstance().scaleWidth * ScreenUtil.pixelRatio}', |
100 | textAlign: TextAlign.center, | 108 | textAlign: TextAlign.center, |
101 | ), | 109 | ), |
102 | Text( | 110 | Text( |
103 | - '高度相对于设计稿放大的比例:${ScreenUtil().scaleHeight * ScreenUtil.pixelRatio}', | 111 | + '高度相对于设计稿放大的比例:${ScreenUtil.getInstance().scaleHeight * ScreenUtil.pixelRatio}', |
104 | textAlign: TextAlign.center, | 112 | textAlign: TextAlign.center, |
105 | ), | 113 | ), |
106 | SizedBox( | 114 | SizedBox( |
107 | - height: ScreenUtil().setHeight(100), | 115 | + height: ScreenUtil.getInstance().setHeight(100), |
108 | ), | 116 | ), |
109 | Text('系统的字体缩放比例:${ScreenUtil.textScaleFactory}'), | 117 | Text('系统的字体缩放比例:${ScreenUtil.textScaleFactory}'), |
110 | Column( | 118 | Column( |
@@ -112,10 +120,12 @@ class _MyHomePageState extends State<MyHomePage> { | @@ -112,10 +120,12 @@ class _MyHomePageState extends State<MyHomePage> { | ||
112 | children: <Widget>[ | 120 | children: <Widget>[ |
113 | Text('我的文字大小在设计稿上是25px,不会随着系统的文字缩放比例变化', | 121 | Text('我的文字大小在设计稿上是25px,不会随着系统的文字缩放比例变化', |
114 | style: TextStyle( | 122 | style: TextStyle( |
115 | - color: Colors.black, fontSize: ScreenUtil().setSp(24))), | 123 | + color: Colors.black, fontSize: ScreenUtil.getInstance().setSp(24))), |
116 | Text('我的文字大小在设计稿上是25px,会随着系统的文字缩放比例变化', | 124 | Text('我的文字大小在设计稿上是25px,会随着系统的文字缩放比例变化', |
117 | style: TextStyle( | 125 | style: TextStyle( |
118 | - color: Colors.black, fontSize: ScreenUtil(allowFontScaling: true).setSp(24))), | 126 | + color: Colors.black, |
127 | + fontSize: | ||
128 | + ScreenUtil(allowFontScaling: true).setSp(24))), | ||
119 | ], | 129 | ], |
120 | ) | 130 | ) |
121 | ], | 131 | ], |
@@ -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.5" | 50 | + version: "0.5.0" |
51 | flutter_test: | 51 | flutter_test: |
52 | dependency: "direct dev" | 52 | dependency: "direct dev" |
53 | description: flutter | 53 | description: flutter |
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.6 | 3 | +version: 0.5.0 |
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