Showing
2 changed files
with
23 additions
and
11 deletions
@@ -35,7 +35,9 @@ class ScreenUtil { | @@ -35,7 +35,9 @@ class ScreenUtil { | ||
35 | } | 35 | } |
36 | 36 | ||
37 | static void init( | 37 | static void init( |
38 | - BoxConstraints constraints, { | 38 | + BoxConstraints constraints, |
39 | + Orientation orientation, | ||
40 | + { | ||
39 | Size designSize = defaultSize, | 41 | Size designSize = defaultSize, |
40 | bool allowFontScaling = false, | 42 | bool allowFontScaling = false, |
41 | }) { | 43 | }) { |
@@ -43,8 +45,13 @@ class ScreenUtil { | @@ -43,8 +45,13 @@ class ScreenUtil { | ||
43 | _instance | 45 | _instance |
44 | ..uiSize = designSize | 46 | ..uiSize = designSize |
45 | ..allowFontScaling = allowFontScaling; | 47 | ..allowFontScaling = allowFontScaling; |
46 | - _screenWidth = constraints.maxWidth; | 48 | + if(orientation == Orientation.potrait){ |
49 | + _screenWidth = constraints.maxWidth; | ||
47 | _screenHeight = constraints.maxHeight; | 50 | _screenHeight = constraints.maxHeight; |
51 | + }else{ | ||
52 | + _screenWidth = constraints.maxHeight; | ||
53 | + _screenHeight = constraints.maxWidth; | ||
54 | + } | ||
48 | 55 | ||
49 | var window = WidgetsBinding.instance?.window ?? ui.window; | 56 | var window = WidgetsBinding.instance?.window ?? ui.window; |
50 | _pixelRatio = window.devicePixelRatio; | 57 | _pixelRatio = window.devicePixelRatio; |
@@ -22,16 +22,21 @@ class ScreenUtilInit extends StatelessWidget { | @@ -22,16 +22,21 @@ class ScreenUtilInit extends StatelessWidget { | ||
22 | @override | 22 | @override |
23 | Widget build(BuildContext context) { | 23 | Widget build(BuildContext context) { |
24 | return LayoutBuilder( | 24 | return LayoutBuilder( |
25 | - // ignore: missing_return | ||
26 | builder: (_, BoxConstraints constraints) { | 25 | builder: (_, BoxConstraints constraints) { |
27 | - if (constraints.maxWidth != 0) { | ||
28 | - ScreenUtil.init( | ||
29 | - constraints, | ||
30 | - designSize: designSize, | ||
31 | - allowFontScaling: allowFontScaling, | ||
32 | - ); | ||
33 | - } | ||
34 | - return builder(); | 26 | + return OrientationBuilder( |
27 | + builder: (_, Orientation orientation) { | ||
28 | + // ignore: missing_return | ||
29 | + if (constraints.maxWidth != 0) { | ||
30 | + ScreenUtil.init( | ||
31 | + constraints, | ||
32 | + orientation, | ||
33 | + designSize: designSize, | ||
34 | + allowFontScaling: allowFontScaling, | ||
35 | + ); | ||
36 | + } | ||
37 | + return builder(); | ||
38 | + }, | ||
39 | + ); | ||
35 | }, | 40 | }, |
36 | ); | 41 | ); |
37 | } | 42 | } |
-
Please register or login to post a comment