Sushil Ghorasaini

Fixing size changes on device orientation change

... ... @@ -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;
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;
... ...
... ... @@ -22,11 +22,14 @@ class ScreenUtilInit extends StatelessWidget {
@override
Widget build(BuildContext context) {
return LayoutBuilder(
// ignore: missing_return
builder: (_, BoxConstraints constraints) {
return OrientationBuilder(
builder: (_, Orientation orientation) {
// ignore: missing_return
if (constraints.maxWidth != 0) {
ScreenUtil.init(
constraints,
orientation,
designSize: designSize,
allowFontScaling: allowFontScaling,
);
... ... @@ -34,5 +37,7 @@ class ScreenUtilInit extends StatelessWidget {
return builder();
},
);
},
);
}
}
... ...