responsiveWidth static method

double responsiveWidth(
  1. BuildContext context, {
  2. double mobileRatio = 1.0,
  3. double tabletRatio = 0.8,
  4. double desktopRatio = 0.6,
  5. double? maxWidth,
})

Implementation

static double responsiveWidth(
  BuildContext context, {
  double mobileRatio = 1.0,
  double tabletRatio = 0.8,
  double desktopRatio = 0.6,
  double? maxWidth,
}) {
  final screenWidth = MediaQuery.of(context).size.width;
  double width;

  if (isDesktop(context)) {
    width = screenWidth * desktopRatio;
  } else if (isTablet(context)) {
    width = screenWidth * tabletRatio;
  } else {
    width = screenWidth * mobileRatio;
  }

  if (maxWidth != null && width > maxWidth) {
    width = maxWidth;
  }

  return width;
}