diff --git a/lib/screenutil.dart b/lib/screenutil.dart index b9e2061..59e84b0 100644 --- a/lib/screenutil.dart +++ b/lib/screenutil.dart @@ -35,7 +35,9 @@ class ScreenUtil { } static void init( - BoxConstraints constraints, { + BoxConstraints constraints, + Orientation orientation, + { Size designSize = defaultSize, bool allowFontScaling = false, }) { @@ -43,8 +45,13 @@ class ScreenUtil { _instance ..uiSize = designSize ..allowFontScaling = allowFontScaling; - _screenWidth = constraints.maxWidth; + if(orientation == Orientation.potrait){ + _screenWidth = constraints.maxWidth; _screenHeight = constraints.maxHeight; + }else{ + _screenWidth = constraints.maxHeight; + _screenHeight = constraints.maxWidth; + } var window = WidgetsBinding.instance?.window ?? ui.window; _pixelRatio = window.devicePixelRatio; diff --git a/lib/screenutil_init.dart b/lib/screenutil_init.dart index 50a0631..666b639 100644 --- a/lib/screenutil_init.dart +++ b/lib/screenutil_init.dart @@ -22,16 +22,21 @@ class ScreenUtilInit extends StatelessWidget { @override Widget build(BuildContext context) { return LayoutBuilder( - // ignore: missing_return builder: (_, BoxConstraints constraints) { - if (constraints.maxWidth != 0) { - ScreenUtil.init( - constraints, - designSize: designSize, - allowFontScaling: allowFontScaling, - ); - } - return builder(); + return OrientationBuilder( + builder: (_, Orientation orientation) { + // ignore: missing_return + if (constraints.maxWidth != 0) { + ScreenUtil.init( + constraints, + orientation, + designSize: designSize, + allowFontScaling: allowFontScaling, + ); + } + return builder(); + }, + ); }, ); }