Simon

feat: support for disabling scaling

... ... @@ -15,6 +15,10 @@ class ScreenUtil {
static const Size defaultSize = Size(360, 690);
static ScreenUtil _instance = ScreenUtil._();
static bool Function() _enableScaleWH = () => true;
static bool Function() _enableScaleText = () => true;
/// UI设计中手机尺寸 , dp
/// Size of the phone in UI Design , dp
late Size _uiSize;
... ... @@ -31,6 +35,16 @@ class ScreenUtil {
factory ScreenUtil() => _instance;
/// Enable scale
///
/// if the enableWH return false, the width and the height scale ratio will be 1
/// if the enableText return false, the text scale ratio will be 1
///
static void enableScale({bool Function()? enableWH, bool Function()? enableText}) {
_enableScaleWH = enableWH ?? () => true;
_enableScaleText = enableText ?? () => true;
}
/// Manually wait for window size to be initialized
///
/// `Recommended` to use before you need access window size
... ... @@ -197,15 +211,15 @@ class ScreenUtil {
/// 实际尺寸与UI设计的比例
/// The ratio of actual width to UI design
double get scaleWidth => screenWidth / _uiSize.width;
double get scaleWidth => !_enableScaleWH() ? 1 : screenWidth / _uiSize.width;
/// The ratio of actual height to UI design
double get scaleHeight =>
(_splitScreenMode ? max(screenHeight, 700) : screenHeight) /
!_enableScaleWH() ? 1 : (_splitScreenMode ? max(screenHeight, 700) : screenHeight) /
_uiSize.height;
double get scaleText =>
_minTextAdapt ? min(scaleWidth, scaleHeight) : scaleWidth;
!_enableScaleText() ? 1 : (_minTextAdapt ? min(scaleWidth, scaleHeight) : scaleWidth);
/// 根据UI设计的设备宽度适配
/// 高度也可以根据这个来做适配可以保证不变形,比如你想要一个正方形的时候.
... ...