李卓原

fix initial problem

@@ -10,7 +10,7 @@ import 'package:flutter/material.dart'; @@ -10,7 +10,7 @@ import 'package:flutter/material.dart';
10 10
11 class ScreenUtil { 11 class ScreenUtil {
12 static const Size defaultSize = Size(360, 690); 12 static const Size defaultSize = Size(360, 690);
13 - static late ScreenUtil _instance; 13 + static ScreenUtil _instance = ScreenUtil._();
14 14
15 /// UI设计中手机尺寸 , dp 15 /// UI设计中手机尺寸 , dp
16 /// Size of the phone in UI Design , dp 16 /// Size of the phone in UI Design , dp
@@ -21,14 +21,14 @@ class ScreenUtil { @@ -21,14 +21,14 @@ class ScreenUtil {
21 late bool allowFontScaling; 21 late bool allowFontScaling;
22 22
23 ///屏幕方向 23 ///屏幕方向
24 - static late Orientation _orientation; 24 + late Orientation _orientation;
25 25
26 - static late double _pixelRatio;  
27 - static late double _textScaleFactor;  
28 - static late double _screenWidth;  
29 - static late double _screenHeight;  
30 - static late double _statusBarHeight;  
31 - static late double _bottomBarHeight; 26 + late double _pixelRatio;
  27 + late double _textScaleFactor;
  28 + late double _screenWidth;
  29 + late double _screenHeight;
  30 + late double _statusBarHeight;
  31 + late double _bottomBarHeight;
32 32
33 ScreenUtil._(); 33 ScreenUtil._();
34 34
@@ -42,25 +42,24 @@ class ScreenUtil { @@ -42,25 +42,24 @@ class ScreenUtil {
42 Size designSize = defaultSize, 42 Size designSize = defaultSize,
43 bool allowFontScaling = false, 43 bool allowFontScaling = false,
44 }) { 44 }) {
45 - _instance = ScreenUtil._();  
46 _instance 45 _instance
47 ..uiSize = designSize 46 ..uiSize = designSize
48 - ..allowFontScaling = allowFontScaling; 47 + ..allowFontScaling = allowFontScaling
  48 + .._orientation = orientation;
49 49
50 - _orientation = orientation;  
51 if (orientation == Orientation.portrait) { 50 if (orientation == Orientation.portrait) {
52 - _screenWidth = constraints.maxWidth;  
53 - _screenHeight = constraints.maxHeight; 51 + _instance._screenWidth = constraints.maxWidth;
  52 + _instance._screenHeight = constraints.maxHeight;
54 } else { 53 } else {
55 - _screenWidth = constraints.maxHeight;  
56 - _screenHeight = constraints.maxWidth; 54 + _instance._screenWidth = constraints.maxHeight;
  55 + _instance._screenHeight = constraints.maxWidth;
57 } 56 }
58 57
59 var window = WidgetsBinding.instance?.window ?? ui.window; 58 var window = WidgetsBinding.instance?.window ?? ui.window;
60 - _pixelRatio = window.devicePixelRatio;  
61 - _statusBarHeight = window.padding.top;  
62 - _bottomBarHeight = window.padding.bottom;  
63 - _textScaleFactor = window.textScaleFactor; 59 + _instance._pixelRatio = window.devicePixelRatio;
  60 + _instance._statusBarHeight = window.padding.top;
  61 + _instance._bottomBarHeight = window.padding.bottom;
  62 + _instance._textScaleFactor = window.textScaleFactor;
64 } 63 }
65 64
66 ///获取屏幕方向 65 ///获取屏幕方向