Showing
2 changed files
with
14 additions
and
2 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; |
| 48 | + if(orientation == Orientation.potrait){ | ||
| 46 | _screenWidth = constraints.maxWidth; | 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,11 +22,14 @@ class ScreenUtilInit extends StatelessWidget { | @@ -22,11 +22,14 @@ 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) { |
| 26 | + return OrientationBuilder( | ||
| 27 | + builder: (_, Orientation orientation) { | ||
| 28 | + // ignore: missing_return | ||
| 27 | if (constraints.maxWidth != 0) { | 29 | if (constraints.maxWidth != 0) { |
| 28 | ScreenUtil.init( | 30 | ScreenUtil.init( |
| 29 | constraints, | 31 | constraints, |
| 32 | + orientation, | ||
| 30 | designSize: designSize, | 33 | designSize: designSize, |
| 31 | allowFontScaling: allowFontScaling, | 34 | allowFontScaling: allowFontScaling, |
| 32 | ); | 35 | ); |
| @@ -34,5 +37,7 @@ class ScreenUtilInit extends StatelessWidget { | @@ -34,5 +37,7 @@ class ScreenUtilInit extends StatelessWidget { | ||
| 34 | return builder(); | 37 | return builder(); |
| 35 | }, | 38 | }, |
| 36 | ); | 39 | ); |
| 40 | + }, | ||
| 41 | + ); | ||
| 37 | } | 42 | } |
| 38 | } | 43 | } |
-
Please register or login to post a comment