@@ -15,6 +15,10 @@ class ScreenUtil {
15
15
static const Size defaultSize = Size (360 , 690 );
16
16
static ScreenUtil _instance = ScreenUtil ._();
17
17
18
+ static bool Function () _enableScaleWH = () => true ;
19
+ static bool Function () _enableScaleText = () => true ;
20
+
21
+
18
22
/// UI设计中手机尺寸 , dp
19
23
/// Size of the phone in UI Design , dp
20
24
late Size _uiSize;
@@ -31,6 +35,16 @@ class ScreenUtil {
31
35
32
36
factory ScreenUtil () => _instance;
33
37
38
+ /// Enable scale
39
+ ///
40
+ /// if the enableWH return false, the width and the height scale ratio will be 1
41
+ /// if the enableText return false, the text scale ratio will be 1
42
+ ///
43
+ static void enableScale ({bool Function ()? enableWH, bool Function ()? enableText}) {
44
+ _enableScaleWH = enableWH ?? () => true ;
45
+ _enableScaleText = enableText ?? () => true ;
46
+ }
47
+
34
48
/// Manually wait for window size to be initialized
35
49
///
36
50
/// `Recommended` to use before you need access window size
@@ -197,15 +211,15 @@ class ScreenUtil {
197
211
198
212
/// 实际尺寸与UI设计的比例
199
213
/// The ratio of actual width to UI design
200
- double get scaleWidth => screenWidth / _uiSize.width;
214
+ double get scaleWidth => ! _enableScaleWH () ? 1 : screenWidth / _uiSize.width;
201
215
202
216
/// The ratio of actual height to UI design
203
217
double get scaleHeight =>
204
- (_splitScreenMode ? max (screenHeight, 700 ) : screenHeight) /
218
+ ! _enableScaleWH () ? 1 : (_splitScreenMode ? max (screenHeight, 700 ) : screenHeight) /
205
219
_uiSize.height;
206
220
207
221
double get scaleText =>
208
- _minTextAdapt ? min (scaleWidth, scaleHeight) : scaleWidth;
222
+ ! _enableScaleText () ? 1 : ( _minTextAdapt ? min (scaleWidth, scaleHeight) : scaleWidth) ;
209
223
210
224
/// 根据UI设计的设备宽度适配
211
225
/// 高度也可以根据这个来做适配可以保证不变形,比如你想要一个正方形的时候.
0 commit comments