Skip to content

Commit c31fffe

Browse files
committed
feat: support for disabling scaling
1 parent b780eb7 commit c31fffe

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

lib/src/screen_util.dart

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ class ScreenUtil {
1515
static const Size defaultSize = Size(360, 690);
1616
static ScreenUtil _instance = ScreenUtil._();
1717

18+
static bool Function() _enableScaleWH = () => true;
19+
static bool Function() _enableScaleText = () => true;
20+
21+
1822
/// UI设计中手机尺寸 , dp
1923
/// Size of the phone in UI Design , dp
2024
late Size _uiSize;
@@ -31,6 +35,16 @@ class ScreenUtil {
3135

3236
factory ScreenUtil() => _instance;
3337

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+
3448
/// Manually wait for window size to be initialized
3549
///
3650
/// `Recommended` to use before you need access window size
@@ -197,15 +211,15 @@ class ScreenUtil {
197211

198212
/// 实际尺寸与UI设计的比例
199213
/// The ratio of actual width to UI design
200-
double get scaleWidth => screenWidth / _uiSize.width;
214+
double get scaleWidth => !_enableScaleWH() ? 1 : screenWidth / _uiSize.width;
201215

202216
/// The ratio of actual height to UI design
203217
double get scaleHeight =>
204-
(_splitScreenMode ? max(screenHeight, 700) : screenHeight) /
218+
!_enableScaleWH() ? 1 : (_splitScreenMode ? max(screenHeight, 700) : screenHeight) /
205219
_uiSize.height;
206220

207221
double get scaleText =>
208-
_minTextAdapt ? min(scaleWidth, scaleHeight) : scaleWidth;
222+
!_enableScaleText() ? 1 : (_minTextAdapt ? min(scaleWidth, scaleHeight) : scaleWidth);
209223

210224
/// 根据UI设计的设备宽度适配
211225
/// 高度也可以根据这个来做适配可以保证不变形,比如你想要一个正方形的时候.

0 commit comments

Comments
 (0)