Showing
10 changed files
with
105 additions
and
109 deletions
.flutter_tool_state
0 → 100644
@@ -5,6 +5,11 @@ | @@ -5,6 +5,11 @@ | ||
5 | * @LastEditTime: 2020年6月20日 11:20:02 | 5 | * @LastEditTime: 2020年6月20日 11:20:02 |
6 | * @Description: Update log | 6 | * @Description: Update log |
7 | --> | 7 | --> |
8 | + | ||
9 | +# 3.1.0 | ||
10 | +- Use the way back to v2 version | ||
11 | +- Modify registration method | ||
12 | + | ||
8 | # 3.0.2+1 | 13 | # 3.0.2+1 |
9 | - Guide users to use V2 version | 14 | - Guide users to use V2 version |
10 | 15 |
1 | -# Please use [v2](https://pub.flutter-io.cn/packages/flutter_screenutil/versions/2.3.1),[v3](https://pub.flutter-io.cn/packages/flutter_screenutil/versions/3.0.2) now has some bugs. | ||
2 | - | ||
3 | # flutter_screenutil | 1 | # flutter_screenutil |
4 | [](https://pub.dev/packages/flutter_screenutil) | 2 | [](https://pub.dev/packages/flutter_screenutil) |
5 | 3 | ||
@@ -30,7 +28,7 @@ dependencies: | @@ -30,7 +28,7 @@ dependencies: | ||
30 | flutter: | 28 | flutter: |
31 | sdk: flutter | 29 | sdk: flutter |
32 | # add flutter_screenutil | 30 | # add flutter_screenutil |
33 | - flutter_screenutil: ^2.3.1 | 31 | + flutter_screenutil: ^3.1.0 |
34 | ``` | 32 | ``` |
35 | ### Add the following imports to your Dart code: | 33 | ### Add the following imports to your Dart code: |
36 | ``` | 34 | ``` |
@@ -59,13 +57,13 @@ void main() { | @@ -59,13 +57,13 @@ void main() { | ||
59 | //fill in the screen size of the device in the design | 57 | //fill in the screen size of the device in the design |
60 | 58 | ||
61 | //default value : width : 1080px , height:1920px , allowFontScaling:false | 59 | //default value : width : 1080px , height:1920px , allowFontScaling:false |
62 | -ScreenUtil.init(); | 60 | +ScreenUtil.init(context); |
63 | 61 | ||
64 | //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) |
65 | -ScreenUtil.init(designSize: Size(750, 1334)); | 63 | +ScreenUtil.init(context, designSize: Size(750, 1334)); |
66 | 64 | ||
67 | //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 |
68 | -ScreenUtil.init(designSize: Size(750, 1334), allowFontScaling: true); | 66 | +ScreenUtil.init(context, designSize: Size(750, 1334), allowFontScaling: true); |
69 | 67 | ||
70 | ``` | 68 | ``` |
71 | 69 |
1 | -# 请使用[v2](https://pub.flutter-io.cn/packages/flutter_screenutil/versions/2.3.1),[v3](https://pub.flutter-io.cn/packages/flutter_screenutil/versions/3.0.2)现在有一些bug | ||
2 | - | ||
3 | # flutter_ScreenUtil | 1 | # flutter_ScreenUtil |
4 | 2 | ||
5 | [](https://pub.dartlang.org/packages/flutter_screenutil) | 3 | [](https://pub.dartlang.org/packages/flutter_screenutil) |
@@ -35,7 +33,7 @@ dependencies: | @@ -35,7 +33,7 @@ dependencies: | ||
35 | flutter: | 33 | flutter: |
36 | sdk: flutter | 34 | sdk: flutter |
37 | # 添加依赖 | 35 | # 添加依赖 |
38 | - flutter_screenutil: ^2.3.1 | 36 | + flutter_screenutil: ^3.1.0 |
39 | ``` | 37 | ``` |
40 | ### 在每个使用的地方导入包: | 38 | ### 在每个使用的地方导入包: |
41 | ``` | 39 | ``` |
@@ -64,13 +62,13 @@ void main() { | @@ -64,13 +62,13 @@ void main() { | ||
64 | } | 62 | } |
65 | 63 | ||
66 | //默认 width : 1080px , height:1920px , allowFontScaling:false | 64 | //默认 width : 1080px , height:1920px , allowFontScaling:false |
67 | -ScreenUtil.init(); | 65 | +ScreenUtil.init(context); |
68 | 66 | ||
69 | //假如设计稿是按iPhone6的尺寸设计的(iPhone6 750*1334) | 67 | //假如设计稿是按iPhone6的尺寸设计的(iPhone6 750*1334) |
70 | -ScreenUtil.init(designSize: Size(750, 1334)); | 68 | +ScreenUtil.init(context, designSize: Size(750, 1334)); |
71 | 69 | ||
72 | //设置字体大小根据系统的“字体大小”辅助选项来进行缩放,默认为false | 70 | //设置字体大小根据系统的“字体大小”辅助选项来进行缩放,默认为false |
73 | -ScreenUtil.init(designSize: Size(750, 1334), allowFontScaling: true); | 71 | +ScreenUtil.init(context, designSize: Size(750, 1334), allowFontScaling: true); |
74 | 72 | ||
75 | ``` | 73 | ``` |
76 | 74 | ||
@@ -182,12 +180,10 @@ Column( | @@ -182,12 +180,10 @@ Column( | ||
182 | ``` | 180 | ``` |
183 | 181 | ||
184 | ```dart | 182 | ```dart |
185 | -void main() { | ||
186 | - WidgetsFlutterBinding.ensureInitialized(); | ||
187 | - //设置适配尺寸 (填入设计稿中设备的屏幕尺寸) 此处假如设计稿是按iPhone6的尺寸设计的(iPhone6 750*1334) | ||
188 | - ScreenUtil.init(designSize: Size(750, 1334), allowFontScaling: false); | ||
189 | - runApp(MyApp()); | ||
190 | -} | 183 | +import 'package:flutter/material.dart'; |
184 | +import 'package:flutter_screenutil/flutter_screenutil.dart'; | ||
185 | + | ||
186 | +void main() => runApp(MyApp()); | ||
191 | 187 | ||
192 | class MyApp extends StatelessWidget { | 188 | class MyApp extends StatelessWidget { |
193 | @override | 189 | @override |
@@ -198,11 +194,20 @@ class MyApp extends StatelessWidget { | @@ -198,11 +194,20 @@ class MyApp extends StatelessWidget { | ||
198 | theme: ThemeData( | 194 | theme: ThemeData( |
199 | primarySwatch: Colors.blue, | 195 | primarySwatch: Colors.blue, |
200 | ), | 196 | ), |
201 | - home: ExampleWidget(title: 'FlutterScreenUtil示例'), | 197 | + home: MyHomePage(), |
202 | ); | 198 | ); |
203 | } | 199 | } |
204 | } | 200 | } |
205 | 201 | ||
202 | +class MyHomePage extends StatelessWidget { | ||
203 | + @override | ||
204 | + Widget build(BuildContext context) { | ||
205 | + //设置适配尺寸 (填入设计稿中设备的屏幕尺寸) 此处假如设计稿是按iPhone6的尺寸设计的(iPhone6 750*1334) | ||
206 | + ScreenUtil.init(context, designSize: Size(750, 1334), allowFontScaling: false); | ||
207 | + return ExampleWidget(title: 'FlutterScreenUtil 示例'); | ||
208 | + } | ||
209 | +} | ||
210 | + | ||
206 | class ExampleWidget extends StatefulWidget { | 211 | class ExampleWidget extends StatefulWidget { |
207 | const ExampleWidget({Key key, this.title}) : super(key: key); | 212 | const ExampleWidget({Key key, this.title}) : super(key: key); |
208 | 213 | ||
@@ -234,8 +239,7 @@ class _ExampleWidgetState extends State<ExampleWidget> { | @@ -234,8 +239,7 @@ class _ExampleWidgetState extends State<ExampleWidget> { | ||
234 | child: Text( | 239 | child: Text( |
235 | '我的宽度:${0.5.wp}dp \n' | 240 | '我的宽度:${0.5.wp}dp \n' |
236 | '我的高度:${ScreenUtil().setHeight(200)}dp', | 241 | '我的高度:${ScreenUtil().setHeight(200)}dp', |
237 | - style: TextStyle( | ||
238 | - color: Colors.white, fontSize: ScreenUtil().setSp(24)), | 242 | + style: TextStyle(color: Colors.white, fontSize: ScreenUtil().setSp(24)), |
239 | ), | 243 | ), |
240 | ), | 244 | ), |
241 | Container( | 245 | Container( |
@@ -246,9 +250,7 @@ class _ExampleWidgetState extends State<ExampleWidget> { | @@ -246,9 +250,7 @@ class _ExampleWidgetState extends State<ExampleWidget> { | ||
246 | child: Text( | 250 | child: Text( |
247 | '我的宽度:${375.w}dp \n' | 251 | '我的宽度:${375.w}dp \n' |
248 | '我的高度:${200.h}dp', | 252 | '我的高度:${200.h}dp', |
249 | - style: TextStyle( | ||
250 | - color: Colors.white, | ||
251 | - fontSize: ScreenUtil().setSp(24))), | 253 | + style: TextStyle(color: Colors.white, fontSize: ScreenUtil().setSp(24))), |
252 | ), | 254 | ), |
253 | ], | 255 | ], |
254 | ), | 256 | ), |
@@ -276,11 +278,17 @@ class _ExampleWidgetState extends State<ExampleWidget> { | @@ -276,11 +278,17 @@ class _ExampleWidgetState extends State<ExampleWidget> { | ||
276 | children: <Widget>[ | 278 | children: <Widget>[ |
277 | Text( | 279 | Text( |
278 | '我的文字大小在设计稿上是24px,不会随着系统的文字缩放比例变化', | 280 | '我的文字大小在设计稿上是24px,不会随着系统的文字缩放比例变化', |
279 | - style: ts.t2, | 281 | + style: TextStyle( |
282 | + color: Colors.black, | ||
283 | + fontSize: 24.sp, | ||
284 | + ), | ||
280 | ), | 285 | ), |
281 | Text( | 286 | Text( |
282 | '我的文字大小在设计稿上是24px,会随着系统的文字缩放比例变化', | 287 | '我的文字大小在设计稿上是24px,会随着系统的文字缩放比例变化', |
283 | - style: ts.t1, | 288 | + style: TextStyle( |
289 | + color: Colors.black, | ||
290 | + fontSize: 24.ssp, | ||
291 | + ), | ||
284 | ), | 292 | ), |
285 | ], | 293 | ], |
286 | ) | 294 | ) |
@@ -291,7 +299,8 @@ class _ExampleWidgetState extends State<ExampleWidget> { | @@ -291,7 +299,8 @@ class _ExampleWidgetState extends State<ExampleWidget> { | ||
291 | child: Icon(Icons.title), | 299 | child: Icon(Icons.title), |
292 | onPressed: () { | 300 | onPressed: () { |
293 | ScreenUtil.init( | 301 | ScreenUtil.init( |
294 | - designSize: Size(1500, 1334), | 302 | + context, |
303 | + designSize: Size(750, 1334), | ||
295 | allowFontScaling: false, | 304 | allowFontScaling: false, |
296 | ); | 305 | ); |
297 | setState(() {}); | 306 | setState(() {}); |
1 | -# Please use [v2](https://pub.flutter-io.cn/packages/flutter_screenutil/versions/2.3.1),[v3](https://pub.flutter-io.cn/packages/flutter_screenutil/versions/3.0.2) now has some bugs. | ||
2 | - | ||
3 | # flutter_screenutil | 1 | # flutter_screenutil |
4 | [](https://pub.dartlang.org/packages/flutter_screenutil) | 2 | [](https://pub.dartlang.org/packages/flutter_screenutil) |
5 | 3 | ||
@@ -30,7 +28,7 @@ dependencies: | @@ -30,7 +28,7 @@ dependencies: | ||
30 | flutter: | 28 | flutter: |
31 | sdk: flutter | 29 | sdk: flutter |
32 | # add flutter_screenutil | 30 | # add flutter_screenutil |
33 | - flutter_screenutil: ^2.3.1 | 31 | + flutter_screenutil: ^3.1.0 |
34 | ``` | 32 | ``` |
35 | 33 | ||
36 | ### Adicione o seguinte import em seu código Dart: | 34 | ### Adicione o seguinte import em seu código Dart: |
@@ -60,13 +58,13 @@ void main() { | @@ -60,13 +58,13 @@ void main() { | ||
60 | } | 58 | } |
61 | 59 | ||
62 | //Valor padrão: width : 1080px , height:1920px , allowFontScaling:false | 60 | //Valor padrão: width : 1080px , height:1920px , allowFontScaling:false |
63 | -ScreenUtil.init(); | 61 | +ScreenUtil.init(context); |
64 | 62 | ||
65 | //Se o design é baseado no iPhone6 (iPhone6 750*1334) | 63 | //Se o design é baseado no iPhone6 (iPhone6 750*1334) |
66 | -ScreenUtil.init(designSize: Size(750, 1334)); | 64 | +ScreenUtil.init(context, designSize: Size(750, 1334)); |
67 | 65 | ||
68 | //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 |
69 | -ScreenUtil.init(designSize: Size(750, 1334), allowFontScaling: true); | 67 | +ScreenUtil.init(context, designSize: Size(750, 1334), allowFontScaling: true); |
70 | 68 | ||
71 | ``` | 69 | ``` |
72 | 70 |
@@ -3,14 +3,7 @@ import 'dart:ui'; | @@ -3,14 +3,7 @@ import 'dart:ui'; | ||
3 | import 'package:flutter/material.dart'; | 3 | import 'package:flutter/material.dart'; |
4 | import 'package:flutter_screenutil/flutter_screenutil.dart'; | 4 | import 'package:flutter_screenutil/flutter_screenutil.dart'; |
5 | 5 | ||
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 | -} | 6 | +void main() => runApp(MyApp()); |
14 | 7 | ||
15 | class MyApp extends StatelessWidget { | 8 | class MyApp extends StatelessWidget { |
16 | @override | 9 | @override |
@@ -21,11 +14,20 @@ class MyApp extends StatelessWidget { | @@ -21,11 +14,20 @@ class MyApp extends StatelessWidget { | ||
21 | theme: ThemeData( | 14 | theme: ThemeData( |
22 | primarySwatch: Colors.blue, | 15 | primarySwatch: Colors.blue, |
23 | ), | 16 | ), |
24 | - home: ExampleWidget(title: 'FlutterScreenUtil Demo'), | 17 | + home: MyHomePage(), |
25 | ); | 18 | ); |
26 | } | 19 | } |
27 | } | 20 | } |
28 | 21 | ||
22 | +class MyHomePage extends StatelessWidget { | ||
23 | + @override | ||
24 | + Widget build(BuildContext context) { | ||
25 | + //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) | ||
26 | + ScreenUtil.init(context, designSize: Size(750, 1334), allowFontScaling: false); | ||
27 | + return ExampleWidget(title: 'FlutterScreenUtil Demo'); | ||
28 | + } | ||
29 | +} | ||
30 | + | ||
29 | class ExampleWidget extends StatefulWidget { | 31 | class ExampleWidget extends StatefulWidget { |
30 | const ExampleWidget({Key key, this.title}) : super(key: key); | 32 | const ExampleWidget({Key key, this.title}) : super(key: key); |
31 | 33 | ||
@@ -38,6 +40,9 @@ class ExampleWidget extends StatefulWidget { | @@ -38,6 +40,9 @@ class ExampleWidget extends StatefulWidget { | ||
38 | class _ExampleWidgetState extends State<ExampleWidget> { | 40 | class _ExampleWidgetState extends State<ExampleWidget> { |
39 | @override | 41 | @override |
40 | Widget build(BuildContext context) { | 42 | Widget build(BuildContext context) { |
43 | + //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) | ||
44 | + ScreenUtil.init(context, designSize: Size(750, 1334), allowFontScaling: false); | ||
45 | + | ||
41 | printScreenInformation(); | 46 | printScreenInformation(); |
42 | return Scaffold( | 47 | return Scaffold( |
43 | appBar: AppBar( | 48 | appBar: AppBar( |
@@ -112,7 +117,10 @@ class _ExampleWidgetState extends State<ExampleWidget> { | @@ -112,7 +117,10 @@ class _ExampleWidgetState extends State<ExampleWidget> { | ||
112 | ), | 117 | ), |
113 | Text( | 118 | Text( |
114 | 'My font size is 24px on the design draft and will change with the system.', | 119 | 'My font size is 24px on the design draft and will change with the system.', |
115 | - style: ts.t1, | 120 | + style: TextStyle( |
121 | + color: Colors.black, | ||
122 | + fontSize: 24.ssp, | ||
123 | + ), | ||
116 | ), | 124 | ), |
117 | ], | 125 | ], |
118 | ) | 126 | ) |
@@ -122,10 +130,7 @@ class _ExampleWidgetState extends State<ExampleWidget> { | @@ -122,10 +130,7 @@ class _ExampleWidgetState extends State<ExampleWidget> { | ||
122 | floatingActionButton: FloatingActionButton( | 130 | floatingActionButton: FloatingActionButton( |
123 | child: Icon(Icons.title), | 131 | child: Icon(Icons.title), |
124 | onPressed: () { | 132 | onPressed: () { |
125 | - ScreenUtil.init( | ||
126 | - designSize: Size(750, 1334), | ||
127 | - allowFontScaling: false, | ||
128 | - ); | 133 | + ScreenUtil.init(context, designSize: Size(750, 1334), allowFontScaling: false); |
129 | setState(() {}); | 134 | setState(() {}); |
130 | }, | 135 | }, |
131 | ), | 136 | ), |
@@ -151,4 +156,3 @@ class _ExampleWidgetState extends State<ExampleWidget> { | @@ -151,4 +156,3 @@ class _ExampleWidgetState extends State<ExampleWidget> { | ||
151 | print('0.5 times the screen height:${0.5.hp}'); | 156 | print('0.5 times the screen height:${0.5.hp}'); |
152 | } | 157 | } |
153 | } | 158 | } |
154 | - |
1 | import 'package:flutter/material.dart'; | 1 | import 'package:flutter/material.dart'; |
2 | import 'package:flutter_screenutil/flutter_screenutil.dart'; | 2 | import 'package:flutter_screenutil/flutter_screenutil.dart'; |
3 | 3 | ||
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 | -} | 4 | +void main() => runApp(MyApp()); |
12 | 5 | ||
13 | class MyApp extends StatelessWidget { | 6 | class MyApp extends StatelessWidget { |
14 | @override | 7 | @override |
@@ -19,11 +12,20 @@ class MyApp extends StatelessWidget { | @@ -19,11 +12,20 @@ class MyApp extends StatelessWidget { | ||
19 | theme: ThemeData( | 12 | theme: ThemeData( |
20 | primarySwatch: Colors.blue, | 13 | primarySwatch: Colors.blue, |
21 | ), | 14 | ), |
22 | - home: ExampleWidget(title: 'FlutterScreenUtil示例'), | 15 | + home: MyHomePage(), |
23 | ); | 16 | ); |
24 | } | 17 | } |
25 | } | 18 | } |
26 | 19 | ||
20 | +class MyHomePage extends StatelessWidget { | ||
21 | + @override | ||
22 | + Widget build(BuildContext context) { | ||
23 | + //设置适配尺寸 (填入设计稿中设备的屏幕尺寸) 此处假如设计稿是按iPhone6的尺寸设计的(iPhone6 750*1334) | ||
24 | + ScreenUtil.init(context, designSize: Size(750, 1334), allowFontScaling: false); | ||
25 | + return ExampleWidget(title: 'FlutterScreenUtil 示例'); | ||
26 | + } | ||
27 | +} | ||
28 | + | ||
27 | class ExampleWidget extends StatefulWidget { | 29 | class ExampleWidget extends StatefulWidget { |
28 | const ExampleWidget({Key key, this.title}) : super(key: key); | 30 | const ExampleWidget({Key key, this.title}) : super(key: key); |
29 | 31 | ||
@@ -55,8 +57,7 @@ class _ExampleWidgetState extends State<ExampleWidget> { | @@ -55,8 +57,7 @@ class _ExampleWidgetState extends State<ExampleWidget> { | ||
55 | child: Text( | 57 | child: Text( |
56 | '我的宽度:${0.5.wp}dp \n' | 58 | '我的宽度:${0.5.wp}dp \n' |
57 | '我的高度:${ScreenUtil().setHeight(200)}dp', | 59 | '我的高度:${ScreenUtil().setHeight(200)}dp', |
58 | - style: TextStyle( | ||
59 | - color: Colors.white, fontSize: ScreenUtil().setSp(24)), | 60 | + style: TextStyle(color: Colors.white, fontSize: ScreenUtil().setSp(24)), |
60 | ), | 61 | ), |
61 | ), | 62 | ), |
62 | Container( | 63 | Container( |
@@ -67,9 +68,7 @@ class _ExampleWidgetState extends State<ExampleWidget> { | @@ -67,9 +68,7 @@ class _ExampleWidgetState extends State<ExampleWidget> { | ||
67 | child: Text( | 68 | child: Text( |
68 | '我的宽度:${375.w}dp \n' | 69 | '我的宽度:${375.w}dp \n' |
69 | '我的高度:${200.h}dp', | 70 | '我的高度:${200.h}dp', |
70 | - style: TextStyle( | ||
71 | - color: Colors.white, | ||
72 | - fontSize: ScreenUtil().setSp(24))), | 71 | + style: TextStyle(color: Colors.white, fontSize: ScreenUtil().setSp(24))), |
73 | ), | 72 | ), |
74 | ], | 73 | ], |
75 | ), | 74 | ), |
@@ -97,11 +96,17 @@ class _ExampleWidgetState extends State<ExampleWidget> { | @@ -97,11 +96,17 @@ class _ExampleWidgetState extends State<ExampleWidget> { | ||
97 | children: <Widget>[ | 96 | children: <Widget>[ |
98 | Text( | 97 | Text( |
99 | '我的文字大小在设计稿上是24px,不会随着系统的文字缩放比例变化', | 98 | '我的文字大小在设计稿上是24px,不会随着系统的文字缩放比例变化', |
100 | - style: ts.t2, | 99 | + style: TextStyle( |
100 | + color: Colors.black, | ||
101 | + fontSize: 24.sp, | ||
102 | + ), | ||
101 | ), | 103 | ), |
102 | Text( | 104 | Text( |
103 | '我的文字大小在设计稿上是24px,会随着系统的文字缩放比例变化', | 105 | '我的文字大小在设计稿上是24px,会随着系统的文字缩放比例变化', |
104 | - style: ts.t1, | 106 | + style: TextStyle( |
107 | + color: Colors.black, | ||
108 | + fontSize: 24.ssp, | ||
109 | + ), | ||
105 | ), | 110 | ), |
106 | ], | 111 | ], |
107 | ) | 112 | ) |
@@ -112,6 +117,7 @@ class _ExampleWidgetState extends State<ExampleWidget> { | @@ -112,6 +117,7 @@ class _ExampleWidgetState extends State<ExampleWidget> { | ||
112 | child: Icon(Icons.title), | 117 | child: Icon(Icons.title), |
113 | onPressed: () { | 118 | onPressed: () { |
114 | ScreenUtil.init( | 119 | ScreenUtil.init( |
120 | + context, | ||
115 | designSize: Size(750, 1334), | 121 | designSize: Size(750, 1334), |
116 | allowFontScaling: false, | 122 | allowFontScaling: false, |
117 | ); | 123 | ); |
example/lib/text_style.dart
deleted
100644 → 0
1 | -import 'package:flutter/material.dart'; | ||
2 | -import 'package:flutter_screenutil/flutter_screenutil.dart'; | ||
3 | - | ||
4 | -class TextStyles { | ||
5 | - TextStyle t1 = TextStyle(fontSize: 24.ssp, color: Colors.black); | ||
6 | - TextStyle t2 = TextStyle(fontSize: 24.sp, color: Colors.black); | ||
7 | -} | ||
8 | - | ||
9 | -var ts = TextStyles(); | ||
10 | - | ||
11 | -class TextStyle2 { | ||
12 | - static TextStyle2 ts2; | ||
13 | - | ||
14 | - factory TextStyle2() { | ||
15 | - if (ts2 == null) { | ||
16 | - ts2 = TextStyle2(); | ||
17 | - } | ||
18 | - return ts2; | ||
19 | - } | ||
20 | - | ||
21 | - TextStyle t1 = TextStyle(fontSize: 24.ssp, color: Colors.black); | ||
22 | - TextStyle t2 = TextStyle(fontSize: 24.sp, color: Colors.black); | ||
23 | -} |
@@ -4,7 +4,6 @@ | @@ -4,7 +4,6 @@ | ||
4 | */ | 4 | */ |
5 | 5 | ||
6 | import 'package:flutter/material.dart'; | 6 | import 'package:flutter/material.dart'; |
7 | -import 'package:flutter/scheduler.dart'; | ||
8 | 7 | ||
9 | class ScreenUtil { | 8 | class ScreenUtil { |
10 | static ScreenUtil _instance; | 9 | static ScreenUtil _instance; |
@@ -18,26 +17,14 @@ class ScreenUtil { | @@ -18,26 +17,14 @@ class ScreenUtil { | ||
18 | /// allowFontScaling Specifies whether fonts should scale to respect Text Size accessibility settings. The default is false. | 17 | /// allowFontScaling Specifies whether fonts should scale to respect Text Size accessibility settings. The default is false. |
19 | bool allowFontScaling = false; | 18 | bool allowFontScaling = false; |
20 | 19 | ||
21 | - double _pixelRatio; | ||
22 | - double _screenWidth; | ||
23 | - double _screenHeight; | ||
24 | - double _statusBarHeight; | ||
25 | - double _bottomBarHeight; | ||
26 | - double _textScaleFactor; | 20 | + static double _pixelRatio; |
21 | + static double _screenWidth; | ||
22 | + static double _screenHeight; | ||
23 | + static double _statusBarHeight; | ||
24 | + static double _bottomBarHeight; | ||
25 | + static double _textScaleFactor; | ||
27 | 26 | ||
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 / _pixelRatio; | ||
38 | - _bottomBarHeight = window.padding.bottom / _pixelRatio; | ||
39 | - _textScaleFactor = window.textScaleFactor; | ||
40 | - } | 27 | + ScreenUtil._(); |
41 | 28 | ||
42 | factory ScreenUtil() { | 29 | factory ScreenUtil() { |
43 | assert( | 30 | assert( |
@@ -47,7 +34,8 @@ class ScreenUtil { | @@ -47,7 +34,8 @@ class ScreenUtil { | ||
47 | return _instance; | 34 | return _instance; |
48 | } | 35 | } |
49 | 36 | ||
50 | - static void init({ | 37 | + static void init( |
38 | + BuildContext context, { | ||
51 | Size designSize = defaultSize, | 39 | Size designSize = defaultSize, |
52 | bool allowFontScaling = false, | 40 | bool allowFontScaling = false, |
53 | }) { | 41 | }) { |
@@ -55,6 +43,13 @@ class ScreenUtil { | @@ -55,6 +43,13 @@ class ScreenUtil { | ||
55 | _instance | 43 | _instance |
56 | ..uiSize = designSize | 44 | ..uiSize = designSize |
57 | ..allowFontScaling = allowFontScaling; | 45 | ..allowFontScaling = allowFontScaling; |
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; | ||
58 | } | 53 | } |
59 | 54 | ||
60 | /// 每个逻辑像素的字体像素数,字体的缩放比例 | 55 | /// 每个逻辑像素的字体像素数,字体的缩放比例 |
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: 3.0.2+1 | 3 | +version: 3.1.0 |
4 | homepage: https://github.com/OpenFlutter/flutter_screenutil/tree/beta | 4 | homepage: https://github.com/OpenFlutter/flutter_screenutil/tree/beta |
5 | 5 | ||
6 | environment: | 6 | environment: |
-
Please register or login to post a comment