@@ -10,7 +10,7 @@ import 'package:flutter/material.dart';
1010
1111class ScreenUtil {
1212 static const Size defaultSize = Size (360 , 690 );
13- static late ScreenUtil _instance;
13+ static ScreenUtil _instance = ScreenUtil ._() ;
1414
1515 /// UI设计中手机尺寸 , dp
1616 /// Size of the phone in UI Design , dp
@@ -21,14 +21,14 @@ class ScreenUtil {
2121 late bool allowFontScaling;
2222
2323 ///屏幕方向
24- static late Orientation _orientation;
24+ late Orientation _orientation;
2525
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;
3232
3333 ScreenUtil ._();
3434
@@ -42,25 +42,24 @@ class ScreenUtil {
4242 Size designSize = defaultSize,
4343 bool allowFontScaling = false ,
4444 }) {
45- _instance = ScreenUtil ._();
4645 _instance
4746 ..uiSize = designSize
48- ..allowFontScaling = allowFontScaling;
47+ ..allowFontScaling = allowFontScaling
48+ .._orientation = orientation;
4949
50- _orientation = orientation;
5150 if (orientation == Orientation .portrait) {
52- _screenWidth = constraints.maxWidth;
53- _screenHeight = constraints.maxHeight;
51+ _instance. _screenWidth = constraints.maxWidth;
52+ _instance. _screenHeight = constraints.maxHeight;
5453 } else {
55- _screenWidth = constraints.maxHeight;
56- _screenHeight = constraints.maxWidth;
54+ _instance. _screenWidth = constraints.maxHeight;
55+ _instance. _screenHeight = constraints.maxWidth;
5756 }
5857
5958 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;
6463 }
6564
6665 ///获取屏幕方向
0 commit comments