李卓原

5.0.0,null-safety最终版本.

更新内容参考changelog.md
  1 +# 5.0.0
  2 +-Breaking change. Use a new way to set font scaling
  3 +-Deprecated ssp and nsp
  4 +
1 # 5.0.0-nullsafety.11 5 # 5.0.0-nullsafety.11
2 - revert 5.0.0-nullsafety.10 6 - revert 5.0.0-nullsafety.10
3 - fix #230 7 - fix #230
@@ -35,7 +35,6 @@ import 'package:flutter_screenutil/flutter_screenutil.dart'; @@ -35,7 +35,6 @@ import 'package:flutter_screenutil/flutter_screenutil.dart';
35 |Property|Type|Default Value|Description| 35 |Property|Type|Default Value|Description|
36 |:---|:---|:---|:---| 36 |:---|:---|:---|:---|
37 |designSize|Size|Size(360, 690)|The size of the device in the design draft, in dp| 37 |designSize|Size|Size(360, 690)|The size of the device in the design draft, in dp|
38 -|allowFontScaling|bool|false|Sets whether the font size is scaled according to the system's "font size" assist option|  
39 38
40 ### Initialize and set the fit size and font size to scale according to the system's "font size" accessibility option 39 ### Initialize and set the fit size and font size to scale according to the system's "font size" accessibility option
41 Please set the size of the design draft before use, the width and height of the design draft. 40 Please set the size of the design draft before use, the width and height of the design draft.
@@ -92,7 +91,6 @@ class _HomePageState extends State<HomePage> { @@ -92,7 +91,6 @@ class _HomePageState extends State<HomePage> {
92 maxWidth: MediaQuery.of(context).size.width, 91 maxWidth: MediaQuery.of(context).size.width,
93 maxHeight: MediaQuery.of(context).size.height), 92 maxHeight: MediaQuery.of(context).size.height),
94 designSize: Size(360, 690), 93 designSize: Size(360, 690),
95 - allowFontScaling: false,  
96 orientation: Orientation.portrait); 94 orientation: Orientation.portrait);
97 return Scaffold(); 95 return Scaffold();
98 } 96 }
@@ -110,8 +108,6 @@ class _HomePageState extends State<HomePage> { @@ -110,8 +108,6 @@ class _HomePageState extends State<HomePage> {
110 ScreenUtil().setHeight(200) (dart sdk>=2.6 : 200.h) //Adapted to screen height , under normal circumstances, the height still uses x.w 108 ScreenUtil().setHeight(200) (dart sdk>=2.6 : 200.h) //Adapted to screen height , under normal circumstances, the height still uses x.w
111 ScreenUtil().radius(200) (dart sdk>=2.6 : 200.r) //Adapt according to the smaller of width or height 109 ScreenUtil().radius(200) (dart sdk>=2.6 : 200.r) //Adapt according to the smaller of width or height
112 ScreenUtil().setSp(24) (dart sdk>=2.6 : 24.sp) //Adapter font 110 ScreenUtil().setSp(24) (dart sdk>=2.6 : 24.sp) //Adapter font
113 - ScreenUtil().setSp(24, allowFontScalingSelf: true) (dart sdk>=2.6 : 24.ssp) //Adapter font(fonts will scale to respect Text Size accessibility settings)  
114 - ScreenUtil().setSp(24, allowFontScalingSelf: false) (dart sdk>=2.6 : 24.nsp) //Adapter font(fonts will not scale to respect Text Size accessibility settings)  
115 111
116 ScreenUtil().pixelRatio //Device pixel density 112 ScreenUtil().pixelRatio //Device pixel density
117 ScreenUtil().screenWidth (dart sdk>=2.6 : 1.sw) //Device width 113 ScreenUtil().screenWidth (dart sdk>=2.6 : 1.sw) //Device width
@@ -194,15 +190,6 @@ Container( @@ -194,15 +190,6 @@ Container(
194 ScreenUtil().setSp(28) 190 ScreenUtil().setSp(28)
195 28.sp 191 28.sp
196 192
197 -//Incoming font size,the unit is pixel,fonts will scale to respect Text Size accessibility settings  
198 -//(If somewhere follow the global allowFontScaling setting)  
199 -ScreenUtil().setSp(24, allowFontScalingSelf: true)  
200 -28.ssp  
201 -  
202 -//(If somewhere does not follow the global allowFontScaling setting)  
203 -ScreenUtil().setSp(24, allowFontScalingSelf: false)  
204 -28.nsp  
205 -  
206 //for example: 193 //for example:
207 Column( 194 Column(
208 crossAxisAlignment: CrossAxisAlignment.start, 195 crossAxisAlignment: CrossAxisAlignment.start,
@@ -40,7 +40,6 @@ import 'package:flutter_screenutil/flutter_screenutil.dart'; @@ -40,7 +40,6 @@ import 'package:flutter_screenutil/flutter_screenutil.dart';
40 |属性|类型|默认值|描述| 40 |属性|类型|默认值|描述|
41 |:---|:---|:---|:---| 41 |:---|:---|:---|:---|
42 |designSize|Size|Size(360, 690)|设计稿中设备的尺寸(单位随意,但在使用过程中必须保持一致)| 42 |designSize|Size|Size(360, 690)|设计稿中设备的尺寸(单位随意,但在使用过程中必须保持一致)|
43 -|allowFontScaling|bool|false|设置字体大小是否根据系统的“字体大小”辅助选项来进行缩放|  
44 43
45 ### 初始化并设置适配尺寸及字体大小是否根据系统的“字体大小”辅助选项来进行缩放 44 ### 初始化并设置适配尺寸及字体大小是否根据系统的“字体大小”辅助选项来进行缩放
46 在使用之前请设置好设计稿的宽度和高度,传入设计稿的宽度和高度(单位随意,但在使用过程中必须保持一致) 45 在使用之前请设置好设计稿的宽度和高度,传入设计稿的宽度和高度(单位随意,但在使用过程中必须保持一致)
@@ -103,7 +102,6 @@ class _HomePageState extends State<HomePage> { @@ -103,7 +102,6 @@ class _HomePageState extends State<HomePage> {
103 maxWidth: MediaQuery.of(context).size.width, 102 maxWidth: MediaQuery.of(context).size.width,
104 maxHeight: MediaQuery.of(context).size.height), 103 maxHeight: MediaQuery.of(context).size.height),
105 designSize: Size(360, 690), 104 designSize: Size(360, 690),
106 - allowFontScaling: false,  
107 orientation: Orientation.portrait); 105 orientation: Orientation.portrait);
108 return Scaffold(); 106 return Scaffold();
109 } 107 }
@@ -119,8 +117,6 @@ class _HomePageState extends State<HomePage> { @@ -119,8 +117,6 @@ class _HomePageState extends State<HomePage> {
119 ScreenUtil().setHeight(200) (sdk>=2.6 : 200.h) //根据屏幕高度适配尺寸(一般根据宽度适配即可) 117 ScreenUtil().setHeight(200) (sdk>=2.6 : 200.h) //根据屏幕高度适配尺寸(一般根据宽度适配即可)
120 ScreenUtil().radius(200) (sdk>=2.6 : 200.r) //根据宽度或高度中的较小者进行调整 118 ScreenUtil().radius(200) (sdk>=2.6 : 200.r) //根据宽度或高度中的较小者进行调整
121 ScreenUtil().setSp(24) (sdk>=2.6 : 24.sp) //适配字体 119 ScreenUtil().setSp(24) (sdk>=2.6 : 24.sp) //适配字体
122 - ScreenUtil().setSp(24, allowFontScalingSelf: true) (sdk>=2.6 : 24.ssp) //适配字体(根据系统的“字体大小”辅助选项来进行缩放)  
123 - ScreenUtil().setSp(24, allowFontScalingSelf: false) (sdk>=2.6 : 24.nsp) //适配字体(不会根据系统的“字体大小”辅助选项来进行缩放)  
124 120
125 ScreenUtil.pixelRatio //设备的像素密度 121 ScreenUtil.pixelRatio //设备的像素密度
126 ScreenUtil.screenWidth (sdk>=2.6 : 1.sw) //设备宽度 122 ScreenUtil.screenWidth (sdk>=2.6 : 1.sw) //设备宽度
@@ -197,12 +193,6 @@ ScreenUtil().setSp(28) @@ -197,12 +193,6 @@ ScreenUtil().setSp(28)
197 193
198 28.sp (dart sdk>=2.6) 194 28.sp (dart sdk>=2.6)
199 195
200 -//传入字体大小,根据系统的“字体大小”辅助选项来进行缩放(如果某个地方不遵循全局的allowFontScaling设置)  
201 -ScreenUtil().setSp(24, allowFontScalingSelf: true)  
202 -  
203 -24.ssp (dart sdk>=2.6)  
204 -  
205 -  
206 //for example: 196 //for example:
207 197
208 Column( 198 Column(
@@ -38,7 +38,6 @@ import 'package:flutter_screenutil/flutter_screenutil.dart'; @@ -38,7 +38,6 @@ import 'package:flutter_screenutil/flutter_screenutil.dart';
38 |:---|:---|:---|:---| 38 |:---|:---|:---|:---|
39 |width|double|360dp|A largura do dispositivo no protótipo de design, em dp| 39 |width|double|360dp|A largura do dispositivo no protótipo de design, em dp|
40 |height|double|690dp|A altura do dispositivo no protótipo de design, em dp| 40 |height|double|690dp|A altura do dispositivo no protótipo de design, em dp|
41 -|allowFontScaling|bool|false|Defina caso o tamanho da fonte seja dimensionado de acordo com a opção "tamanho de fonte" na acessibilidade do sistema|  
42 41
43 ### Inicialize e defina o tamanho de ajuste e tamanho da fonte para dimensionar de acordo com a opção "tamanho de fonte" na acessibilidade do sistema 42 ### Inicialize e defina o tamanho de ajuste e tamanho da fonte para dimensionar de acordo com a opção "tamanho de fonte" na acessibilidade do sistema
44 Por favor, defina a largura e altura do protótipo de design antes de usar (em pixels). 43 Por favor, defina a largura e altura do protótipo de design antes de usar (em pixels).
@@ -54,7 +53,6 @@ class MyApp extends StatelessWidget { @@ -54,7 +53,6 @@ class MyApp extends StatelessWidget {
54 //Set the fit size (fill in the screen size of the device in the design,in dp) 53 //Set the fit size (fill in the screen size of the device in the design,in dp)
55 return ScreenUtilInit( 54 return ScreenUtilInit(
56 designSize: Size(360, 690), 55 designSize: Size(360, 690),
57 - allowFontScaling: false,  
58 builder: () => MaterialApp( 56 builder: () => MaterialApp(
59 ... 57 ...
60 ), 58 ),
@@ -112,8 +110,6 @@ class _HomePageState extends State<HomePage> { @@ -112,8 +110,6 @@ class _HomePageState extends State<HomePage> {
112 ScreenUtil().setHeight(200) (sdk>=2.6 : 200.h) //Adapted to screen height 110 ScreenUtil().setHeight(200) (sdk>=2.6 : 200.h) //Adapted to screen height
113 ScreenUtil().radius(200) (dart sdk>=2.6 : 200.r) //Adapt according to the smaller of width or height 111 ScreenUtil().radius(200) (dart sdk>=2.6 : 200.r) //Adapt according to the smaller of width or height
114 ScreenUtil().setSp(24) (sdk>=2.6 : 24.sp) //Adapter font 112 ScreenUtil().setSp(24) (sdk>=2.6 : 24.sp) //Adapter font
115 - ScreenUtil().setSp(24, allowFontScalingSelf: true) (sdk>=2.6 : 24.ssp) //Adapter font(fonts will scale to respect Text Size accessibility settings)  
116 - ScreenUtil().setSp(24, allowFontScalingSelf: false) (sdk>=2.6 : 24.nsp) //Adapter font(fonts will not scale to respect Text Size accessibility settings)  
117 113
118 ScreenUtil.pixelRatio //Device pixel density 114 ScreenUtil.pixelRatio //Device pixel density
119 ScreenUtil.screenWidth (sdk>=2.6 : 1.sw) //Device width 115 ScreenUtil.screenWidth (sdk>=2.6 : 1.sw) //Device width
@@ -189,8 +185,7 @@ Container( @@ -189,8 +185,7 @@ Container(
189 ScreenUtil().setSp(28) 185 ScreenUtil().setSp(28)
190 186
191 //Tamanho da fonte informado,em pixels,a fonte irá dimensionar respeitando a opção "Tamanho de Fonte" nas configurações de acessibilidade 187 //Tamanho da fonte informado,em pixels,a fonte irá dimensionar respeitando a opção "Tamanho de Fonte" nas configurações de acessibilidade
192 -//(Se em algum lugar não seguir a configuração global da propriedade allowFontScaling)  
193 -ScreenUtil().setSp(24, allowFontScalingSelf: true) 188 +ScreenUtil().setSp(24)
194 189
195 //Exemplo: 190 //Exemplo:
196 191
@@ -240,7 +235,7 @@ class MyApp extends StatelessWidget { @@ -240,7 +235,7 @@ class MyApp extends StatelessWidget {
240 return LayoutBuilder( 235 return LayoutBuilder(
241 builder: (context, constraints) { 236 builder: (context, constraints) {
242 //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) 237 //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)
243 - ScreenUtil.init(constraints, designSize: Size(750, 1334), allowFontScaling: false); 238 + ScreenUtil.init(constraints, designSize: Size(750, 1334));
244 239
245 return MaterialApp( 240 return MaterialApp(
246 debugShowCheckedModeBanner: false, 241 debugShowCheckedModeBanner: false,
@@ -10,7 +10,7 @@ @@ -10,7 +10,7 @@
10 void main() { 10 void main() {
11 WidgetsFlutterBinding.ensureInitialized(); 11 WidgetsFlutterBinding.ensureInitialized();
12 //Set the fit size (fill in the screen size of the device in the design) If the design is based on the size of the iPhone6 ​​(iPhone6 ​​750*1334) 12 //Set the fit size (fill in the screen size of the device in the design) If the design is based on the size of the iPhone6 ​​(iPhone6 ​​750*1334)
13 - ScreenUtil.init(designSize: Size(750, 1334), allowFontScaling: false); 13 + ScreenUtil.init(designSize: Size(750, 1334));
14 runApp(MyApp()); 14 runApp(MyApp());
15 } 15 }
16 16
@@ -9,13 +9,19 @@ class MyApp extends StatelessWidget { @@ -9,13 +9,19 @@ class MyApp extends StatelessWidget {
9 //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) 9 //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)
10 return ScreenUtilInit( 10 return ScreenUtilInit(
11 designSize: Size(360, 690), 11 designSize: Size(360, 690),
12 - allowFontScaling: false,  
13 builder: () => MaterialApp( 12 builder: () => MaterialApp(
14 debugShowCheckedModeBanner: false, 13 debugShowCheckedModeBanner: false,
15 title: 'Flutter_ScreenUtil', 14 title: 'Flutter_ScreenUtil',
16 theme: ThemeData( 15 theme: ThemeData(
17 primarySwatch: Colors.blue, 16 primarySwatch: Colors.blue,
18 ), 17 ),
  18 + builder: (context, widget) {
  19 + return MediaQuery(
  20 + //Setting font does not change with system font size
  21 + data: MediaQuery.of(context).copyWith(textScaleFactor: 1.0),
  22 + child: widget,
  23 + );
  24 + },
19 home: HomePage(title: 'FlutterScreenUtil Demo'), 25 home: HomePage(title: 'FlutterScreenUtil Demo'),
20 ), 26 ),
21 ); 27 );
@@ -41,7 +47,7 @@ class _HomePageState extends State<HomePage> { @@ -41,7 +47,7 @@ class _HomePageState extends State<HomePage> {
41 ), 47 ),
42 body: SingleChildScrollView( 48 body: SingleChildScrollView(
43 child: Column( 49 child: Column(
44 - crossAxisAlignment: CrossAxisAlignment.center, 50 + crossAxisAlignment: CrossAxisAlignment.start,
45 children: <Widget>[ 51 children: <Widget>[
46 Row( 52 Row(
47 children: <Widget>[ 53 children: <Widget>[
@@ -82,7 +88,8 @@ class _HomePageState extends State<HomePage> { @@ -82,7 +88,8 @@ class _HomePageState extends State<HomePage> {
82 width: 100.r, 88 width: 100.r,
83 height: 100.r, 89 height: 100.r,
84 color: Colors.green, 90 color: Colors.green,
85 - child: Text('I am a square with a side length of 100', 91 + child: Text(
  92 + 'I am a square with a side length of 100',
86 style: TextStyle( 93 style: TextStyle(
87 color: Colors.white, 94 color: Colors.white,
88 fontSize: ScreenUtil().setSp(12), 95 fontSize: ScreenUtil().setSp(12),
@@ -106,21 +113,23 @@ class _HomePageState extends State<HomePage> { @@ -106,21 +113,23 @@ class _HomePageState extends State<HomePage> {
106 height: 10.h, 113 height: 10.h,
107 ), 114 ),
108 Text('System font scaling factor:${ScreenUtil().textScaleFactor}'), 115 Text('System font scaling factor:${ScreenUtil().textScaleFactor}'),
  116 + SizedBox(height: 5),
109 Column( 117 Column(
110 crossAxisAlignment: CrossAxisAlignment.start, 118 crossAxisAlignment: CrossAxisAlignment.start,
111 children: <Widget>[ 119 children: <Widget>[
112 Text( 120 Text(
113 - 'My font size is 16sp on the design draft and will not change with the system.', 121 + '16sp, will not change with the system.',
114 style: TextStyle( 122 style: TextStyle(
115 color: Colors.black, 123 color: Colors.black,
116 - fontSize: 16.nsp, 124 + fontSize: 16.sp,
117 ), 125 ),
  126 + textScaleFactor: 1.0,
118 ), 127 ),
119 Text( 128 Text(
120 - 'My font size is 16sp on the design draft and will change with the system.', 129 + '16sp,if data is not set in MediaQuery,my font size will change with the system.',
121 style: TextStyle( 130 style: TextStyle(
122 color: Colors.black, 131 color: Colors.black,
123 - fontSize: 16.ssp, 132 + fontSize: 16.sp,
124 ), 133 ),
125 ), 134 ),
126 ], 135 ],
@@ -138,7 +147,8 @@ class _HomePageState extends State<HomePage> { @@ -138,7 +147,8 @@ class _HomePageState extends State<HomePage> {
138 print('Bottom safe zone distance dp:${ScreenUtil().bottomBarHeight}dp'); 147 print('Bottom safe zone distance dp:${ScreenUtil().bottomBarHeight}dp');
139 print('Status bar height dp:${ScreenUtil().statusBarHeight}dp'); 148 print('Status bar height dp:${ScreenUtil().statusBarHeight}dp');
140 print('The ratio of actual width to UI design:${ScreenUtil().scaleWidth}'); 149 print('The ratio of actual width to UI design:${ScreenUtil().scaleWidth}');
141 - print('The ratio of actual height to UI design:${ScreenUtil().scaleHeight}'); 150 + print(
  151 + 'The ratio of actual height to UI design:${ScreenUtil().scaleHeight}');
142 print('System font scaling:${ScreenUtil().textScaleFactor}'); 152 print('System font scaling:${ScreenUtil().textScaleFactor}');
143 print('0.5 times the screen width:${0.5.sw}dp'); 153 print('0.5 times the screen width:${0.5.sw}dp');
144 print('0.5 times the screen height:${0.5.sh}dp'); 154 print('0.5 times the screen height:${0.5.sh}dp');
@@ -35,7 +35,6 @@ class _HomePageState extends State<HomePage> { @@ -35,7 +35,6 @@ class _HomePageState extends State<HomePage> {
35 maxWidth: MediaQuery.of(context).size.width, 35 maxWidth: MediaQuery.of(context).size.width,
36 maxHeight: MediaQuery.of(context).size.height), 36 maxHeight: MediaQuery.of(context).size.height),
37 designSize: Size(360, 690), 37 designSize: Size(360, 690),
38 - allowFontScaling: false,  
39 orientation: Orientation.portrait); 38 orientation: Orientation.portrait);
40 printScreenInformation(); 39 printScreenInformation();
41 return Scaffold( 40 return Scaffold(
@@ -67,7 +66,9 @@ class _HomePageState extends State<HomePage> { @@ -67,7 +66,9 @@ class _HomePageState extends State<HomePage> {
67 child: Text( 66 child: Text(
68 '我的设计稿宽度: 180dp \n' 67 '我的设计稿宽度: 180dp \n'
69 '我的设计稿高度: 200dp', 68 '我的设计稿高度: 200dp',
70 - style: TextStyle(color: Colors.white, fontSize: ScreenUtil().setSp(12))), 69 + style: TextStyle(
  70 + color: Colors.white,
  71 + fontSize: ScreenUtil().setSp(12))),
71 ), 72 ),
72 ], 73 ],
73 ), 74 ),
@@ -105,17 +106,18 @@ class _HomePageState extends State<HomePage> { @@ -105,17 +106,18 @@ class _HomePageState extends State<HomePage> {
105 crossAxisAlignment: CrossAxisAlignment.start, 106 crossAxisAlignment: CrossAxisAlignment.start,
106 children: <Widget>[ 107 children: <Widget>[
107 Text( 108 Text(
108 - '我的文字大小在设计稿上是16dp,不会随着系统的文字缩放比例变化', 109 + '我的文字大小在设计稿上是16dp,因为设置了`textScaleFactor`,所以不会随着系统的文字缩放比例变化',
109 style: TextStyle( 110 style: TextStyle(
110 color: Colors.black, 111 color: Colors.black,
111 fontSize: 16.sp, 112 fontSize: 16.sp,
112 ), 113 ),
  114 + textScaleFactor: 1.0,
113 ), 115 ),
114 Text( 116 Text(
115 '我的文字大小在设计稿上是16dp,会随着系统的文字缩放比例变化', 117 '我的文字大小在设计稿上是16dp,会随着系统的文字缩放比例变化',
116 style: TextStyle( 118 style: TextStyle(
117 color: Colors.black, 119 color: Colors.black,
118 - fontSize: 16.ssp, 120 + fontSize: 16.sp,
119 ), 121 ),
120 ), 122 ),
121 ], 123 ],
@@ -134,8 +136,10 @@ class _HomePageState extends State<HomePage> { @@ -134,8 +136,10 @@ class _HomePageState extends State<HomePage> {
134 print('状态栏高度:${ScreenUtil().statusBarHeight}dp'); 136 print('状态栏高度:${ScreenUtil().statusBarHeight}dp');
135 print('实际宽度的dp与设计稿px的比例:${ScreenUtil().scaleWidth}'); 137 print('实际宽度的dp与设计稿px的比例:${ScreenUtil().scaleWidth}');
136 print('实际高度的dp与设计稿px的比例:${ScreenUtil().scaleHeight}'); 138 print('实际高度的dp与设计稿px的比例:${ScreenUtil().scaleHeight}');
137 - print('宽度和字体相对于设计稿放大的比例:${ScreenUtil().scaleWidth * ScreenUtil().pixelRatio}');  
138 - print('高度相对于设计稿放大的比例:${ScreenUtil().scaleHeight * ScreenUtil().pixelRatio}'); 139 + print(
  140 + '宽度和字体相对于设计稿放大的比例:${ScreenUtil().scaleWidth * ScreenUtil().pixelRatio}');
  141 + print(
  142 + '高度相对于设计稿放大的比例:${ScreenUtil().scaleHeight * ScreenUtil().pixelRatio}');
139 print('系统的字体缩放比例:${ScreenUtil().textScaleFactor}'); 143 print('系统的字体缩放比例:${ScreenUtil().textScaleFactor}');
140 print('屏幕宽度的0.5:${0.5.sw}dp'); 144 print('屏幕宽度的0.5:${0.5.sw}dp');
141 print('屏幕高度的0.5:${0.5.sh}dp'); 145 print('屏幕高度的0.5:${0.5.sh}dp');
@@ -5,6 +5,13 @@ @@ -5,6 +5,13 @@
5 5
6 library flutter_screenutil; 6 library flutter_screenutil;
7 7
8 -export 'size_extension.dart';  
9 -export 'screen_util.dart';  
10 -export 'screenutil_init.dart'; 8 +import 'dart:math';
  9 +import 'dart:ui' as ui;
  10 +
  11 +import 'package:flutter/material.dart';
  12 +
  13 +part 'screen_util.dart';
  14 +
  15 +part 'screenutil_init.dart';
  16 +
  17 +part 'size_extension.dart';
@@ -2,11 +2,7 @@ @@ -2,11 +2,7 @@
2 * Created by 李卓原 on 2018/9/29. 2 * Created by 李卓原 on 2018/9/29.
3 * email: zhuoyuan93@gmail.com 3 * email: zhuoyuan93@gmail.com
4 */ 4 */
5 -  
6 -import 'dart:math';  
7 -import 'dart:ui' as ui;  
8 -  
9 -import 'package:flutter/material.dart'; 5 +part of flutter_screenutil;
10 6
11 class ScreenUtil { 7 class ScreenUtil {
12 static const Size defaultSize = Size(360, 690); 8 static const Size defaultSize = Size(360, 690);
@@ -16,10 +12,6 @@ class ScreenUtil { @@ -16,10 +12,6 @@ class ScreenUtil {
16 /// Size of the phone in UI Design , dp 12 /// Size of the phone in UI Design , dp
17 late Size uiSize; 13 late Size uiSize;
18 14
19 - /// 控制字体是否要根据系统的“字体大小”辅助选项来进行缩放。默认值为false。  
20 - /// allowFontScaling Specifies whether fonts should scale to respect Text Size accessibility settings. The default is false.  
21 - late bool allowFontScaling;  
22 -  
23 ///屏幕方向 15 ///屏幕方向
24 late Orientation _orientation; 16 late Orientation _orientation;
25 17
@@ -40,11 +32,9 @@ class ScreenUtil { @@ -40,11 +32,9 @@ class ScreenUtil {
40 BoxConstraints constraints, { 32 BoxConstraints constraints, {
41 Orientation orientation = Orientation.portrait, 33 Orientation orientation = Orientation.portrait,
42 Size designSize = defaultSize, 34 Size designSize = defaultSize,
43 - bool allowFontScaling = false,  
44 }) { 35 }) {
45 _instance = ScreenUtil._() 36 _instance = ScreenUtil._()
46 ..uiSize = designSize 37 ..uiSize = designSize
47 - ..allowFontScaling = allowFontScaling  
48 .._orientation = orientation 38 .._orientation = orientation
49 .._screenWidth = constraints.maxWidth 39 .._screenWidth = constraints.maxWidth
50 .._screenHeight = constraints.maxHeight; 40 .._screenHeight = constraints.maxHeight;
@@ -118,8 +108,5 @@ class ScreenUtil { @@ -118,8 +108,5 @@ class ScreenUtil {
118 ///- [fontSize] UI设计上字体的大小,单位dp. 108 ///- [fontSize] UI设计上字体的大小,单位dp.
119 ///Font size adaptation method 109 ///Font size adaptation method
120 ///- [fontSize] The size of the font on the UI design, in dp. 110 ///- [fontSize] The size of the font on the UI design, in dp.
121 - ///- [allowFontScaling]  
122 - double setSp(num fontSize, {bool? allowFontScalingSelf}) => allowFontScalingSelf == null  
123 - ? (allowFontScaling ? (fontSize * scaleText) * _textScaleFactor : (fontSize * scaleText))  
124 - : (allowFontScalingSelf ? (fontSize * scaleText) * _textScaleFactor : (fontSize * scaleText)); 111 + double setSp(num fontSize) => fontSize * scaleText;
125 } 112 }
1 -import 'package:flutter/material.dart';  
2 -import 'package:flutter_screenutil/screen_util.dart'; 1 +part of flutter_screenutil;
3 2
4 class ScreenUtilInit extends StatelessWidget { 3 class ScreenUtilInit extends StatelessWidget {
5 /// A helper widget that initializes [ScreenUtil] 4 /// A helper widget that initializes [ScreenUtil]
6 ScreenUtilInit({ 5 ScreenUtilInit({
7 required this.builder, 6 required this.builder,
8 this.designSize = ScreenUtil.defaultSize, 7 this.designSize = ScreenUtil.defaultSize,
9 - this.allowFontScaling = false,  
10 Key? key, 8 Key? key,
11 }) : super(key: key); 9 }) : super(key: key);
12 10
@@ -15,9 +13,6 @@ class ScreenUtilInit extends StatelessWidget { @@ -15,9 +13,6 @@ class ScreenUtilInit extends StatelessWidget {
15 /// The [Size] of the device in the design draft, in dp 13 /// The [Size] of the device in the design draft, in dp
16 final Size designSize; 14 final Size designSize;
17 15
18 - /// Sets whether the font size is scaled according to the system's "font size" assist option  
19 - final bool allowFontScaling;  
20 -  
21 @override 16 @override
22 Widget build(BuildContext context) { 17 Widget build(BuildContext context) {
23 return LayoutBuilder(builder: (_, BoxConstraints constraints) { 18 return LayoutBuilder(builder: (_, BoxConstraints constraints) {
@@ -28,7 +23,6 @@ class ScreenUtilInit extends StatelessWidget { @@ -28,7 +23,6 @@ class ScreenUtilInit extends StatelessWidget {
28 constraints, 23 constraints,
29 orientation: orientation, 24 orientation: orientation,
30 designSize: designSize, 25 designSize: designSize,
31 - allowFontScaling: allowFontScaling,  
32 ); 26 );
33 return builder(); 27 return builder();
34 } 28 }
1 -import 'package:flutter_screenutil/screen_util.dart'; 1 +part of flutter_screenutil;
2 2
3 extension SizeExtension on num { 3 extension SizeExtension on num {
4 ///[ScreenUtil.setWidth] 4 ///[ScreenUtil.setWidth]
@@ -14,10 +14,13 @@ extension SizeExtension on num { @@ -14,10 +14,13 @@ extension SizeExtension on num {
14 double get sp => ScreenUtil().setSp(this); 14 double get sp => ScreenUtil().setSp(this);
15 15
16 ///[ScreenUtil.setSp] 16 ///[ScreenUtil.setSp]
17 - double get ssp => ScreenUtil().setSp(this, allowFontScalingSelf: true); 17 + @Deprecated('please use [sp]')
  18 + double get ssp => ScreenUtil().setSp(this);
18 19
19 ///[ScreenUtil.setSp] 20 ///[ScreenUtil.setSp]
20 - double get nsp => ScreenUtil().setSp(this, allowFontScalingSelf: false); 21 + @Deprecated(
  22 + 'please use [sp] , and set textScaleFactor: 1.0 , for example: Text("text", textScaleFactor: 1.0)')
  23 + double get nsp => ScreenUtil().setSp(this);
21 24
22 ///屏幕宽度的倍数 25 ///屏幕宽度的倍数
23 ///Multiple of screen width 26 ///Multiple of screen width
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: 5.0.0-nullsafety.11 3 +version: 5.0.0
4 homepage: https://github.com/OpenFlutter/flutter_screenutil 4 homepage: https://github.com/OpenFlutter/flutter_screenutil
5 5
6 environment: 6 environment: