Showing
1 changed file
with
17 additions
and
3 deletions
| @@ -15,6 +15,10 @@ class ScreenUtil { | @@ -15,6 +15,10 @@ class ScreenUtil { | ||
| 15 | static const Size defaultSize = Size(360, 690); | 15 | static const Size defaultSize = Size(360, 690); |
| 16 | static ScreenUtil _instance = ScreenUtil._(); | 16 | static ScreenUtil _instance = ScreenUtil._(); |
| 17 | 17 | ||
| 18 | + static bool Function() _enableScaleWH = () => true; | ||
| 19 | + static bool Function() _enableScaleText = () => true; | ||
| 20 | + | ||
| 21 | + | ||
| 18 | /// UI设计中手机尺寸 , dp | 22 | /// UI设计中手机尺寸 , dp |
| 19 | /// Size of the phone in UI Design , dp | 23 | /// Size of the phone in UI Design , dp |
| 20 | late Size _uiSize; | 24 | late Size _uiSize; |
| @@ -31,6 +35,16 @@ class ScreenUtil { | @@ -31,6 +35,16 @@ class ScreenUtil { | ||
| 31 | 35 | ||
| 32 | factory ScreenUtil() => _instance; | 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 | /// Manually wait for window size to be initialized | 48 | /// Manually wait for window size to be initialized |
| 35 | /// | 49 | /// |
| 36 | /// `Recommended` to use before you need access window size | 50 | /// `Recommended` to use before you need access window size |
| @@ -197,15 +211,15 @@ class ScreenUtil { | @@ -197,15 +211,15 @@ class ScreenUtil { | ||
| 197 | 211 | ||
| 198 | /// 实际尺寸与UI设计的比例 | 212 | /// 实际尺寸与UI设计的比例 |
| 199 | /// The ratio of actual width to UI design | 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 | /// The ratio of actual height to UI design | 216 | /// The ratio of actual height to UI design |
| 203 | double get scaleHeight => | 217 | double get scaleHeight => |
| 204 | - (_splitScreenMode ? max(screenHeight, 700) : screenHeight) / | 218 | + !_enableScaleWH() ? 1 : (_splitScreenMode ? max(screenHeight, 700) : screenHeight) / |
| 205 | _uiSize.height; | 219 | _uiSize.height; |
| 206 | 220 | ||
| 207 | double get scaleText => | 221 | double get scaleText => |
| 208 | - _minTextAdapt ? min(scaleWidth, scaleHeight) : scaleWidth; | 222 | + !_enableScaleText() ? 1 : (_minTextAdapt ? min(scaleWidth, scaleHeight) : scaleWidth); |
| 209 | 223 | ||
| 210 | /// 根据UI设计的设备宽度适配 | 224 | /// 根据UI设计的设备宽度适配 |
| 211 | /// 高度也可以根据这个来做适配可以保证不变形,比如你想要一个正方形的时候. | 225 | /// 高度也可以根据这个来做适配可以保证不变形,比如你想要一个正方形的时候. |
-
Please register or login to post a comment