Skip to content

Commit

Permalink
Use MediaQuery.sizeOf to avoid rebuilding multiple times widget
Browse files Browse the repository at this point in the history
  • Loading branch information
dab246 committed Apr 26, 2024
1 parent 9a990d4 commit b14e85d
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions core/lib/presentation/utils/responsive_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ class ResponsiveUtils {
static const double desktopVerticalMargin = 120.0;
static const double desktopHorizontalMargin = 200.0;

bool isScreenWithShortestSide(BuildContext context) => context.mediaQueryShortestSide < minTabletWidth;
bool isScreenWithShortestSide(BuildContext context) => getSizeScreenShortestSide(context) < minTabletWidth;

double getSizeScreenWidth(BuildContext context) => context.width;
double getSizeScreenWidth(BuildContext context) => MediaQuery.sizeOf(context).width;

double getSizeScreenHeight(BuildContext context) => context.height;
double getSizeScreenHeight(BuildContext context) => MediaQuery.sizeOf(context).height;

double getSizeScreenShortestSide(BuildContext context) => context.mediaQueryShortestSide;
double getSizeScreenShortestSide(BuildContext context) => MediaQuery.sizeOf(context).shortestSide;

double getDeviceWidth(BuildContext context) => context.width;
double getDeviceWidth(BuildContext context) => MediaQuery.sizeOf(context).width;

bool isMobile(BuildContext context) => getDeviceWidth(context) < minTabletWidth;

Expand All @@ -46,21 +46,21 @@ class ResponsiveUtils {
bool isLandscapeMobile(BuildContext context) => isScreenWithShortestSide(context) && isLandscape(context);

bool isLandscapeTablet(BuildContext context) {
return context.mediaQueryShortestSide >= minTabletWidth &&
context.mediaQueryShortestSide < minDesktopWidth &&
return getSizeScreenShortestSide(context) >= minTabletWidth &&
getSizeScreenShortestSide(context) < minDesktopWidth &&
isLandscape(context);
}

bool isPortraitMobile(BuildContext context) => isScreenWithShortestSide(context) && isPortrait(context);

bool isPortraitTablet(BuildContext context) {
return context.mediaQueryShortestSide >= minTabletWidth &&
context.mediaQueryShortestSide < minDesktopWidth &&
return getSizeScreenShortestSide(context) >= minTabletWidth &&
getSizeScreenShortestSide(context) < minDesktopWidth &&
isPortrait(context);
}

bool isHeightShortest(BuildContext context) {
return MediaQuery.of(context).size.shortestSide < heightShortest;
return getSizeScreenShortestSide(context) < heightShortest;
}

double getMaxWidthToast(BuildContext context) {
Expand Down

0 comments on commit b14e85d

Please sign in to comment.