Skip to content

Commit

Permalink
Fixing size changes on device orientation change
Browse files Browse the repository at this point in the history
  • Loading branch information
SushilGhorasaini1 committed Feb 10, 2021
1 parent e53982f commit dab45b8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
11 changes: 9 additions & 2 deletions lib/screenutil.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,23 @@ class ScreenUtil {
}

static void init(
BoxConstraints constraints, {
BoxConstraints constraints,
Orientation orientation,
{
Size designSize = defaultSize,
bool allowFontScaling = false,
}) {
_instance = 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;
Expand Down
23 changes: 14 additions & 9 deletions lib/screenutil_init.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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();
},
);
},
);
}
Expand Down

0 comments on commit dab45b8

Please sign in to comment.