Skip to content

Commit 6ddfa4e

Browse files
authored
Merge pull request #216 from SushilGhorasaini1/patch-2
Fixing size changes on device orientation change
2 parents ae9af6d + dab45b8 commit 6ddfa4e

File tree

2 files changed

+23
-11
lines changed

2 files changed

+23
-11
lines changed

lib/screenutil.dart

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,23 @@ class ScreenUtil {
3535
}
3636

3737
static void init(
38-
BoxConstraints constraints, {
38+
BoxConstraints constraints,
39+
Orientation orientation,
40+
{
3941
Size designSize = defaultSize,
4042
bool allowFontScaling = false,
4143
}) {
4244
_instance = ScreenUtil._();
4345
_instance
4446
..uiSize = designSize
4547
..allowFontScaling = allowFontScaling;
46-
_screenWidth = constraints.maxWidth;
48+
if(orientation == Orientation.potrait){
49+
_screenWidth = constraints.maxWidth;
4750
_screenHeight = constraints.maxHeight;
51+
}else{
52+
_screenWidth = constraints.maxHeight;
53+
_screenHeight = constraints.maxWidth;
54+
}
4855

4956
var window = WidgetsBinding.instance?.window ?? ui.window;
5057
_pixelRatio = window.devicePixelRatio;

lib/screenutil_init.dart

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,21 @@ class ScreenUtilInit extends StatelessWidget {
2222
@override
2323
Widget build(BuildContext context) {
2424
return LayoutBuilder(
25-
// ignore: missing_return
2625
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+
);
3540
},
3641
);
3742
}

0 commit comments

Comments
 (0)