cGetResGridRatio function

double cGetResGridRatio(
  1. {required BuildContext context,
  2. required int height,
  3. required int width,
  4. bool logData = false,
  5. double? discardSize}
)

Calculate the responsive childAspectRatio for a GridView based on item dimensions.

This function calculates the childAspectRatio for a GridView based on the provided height and width of the grid items. It takes into account the available screen width (context.cWidth) and an optional discardSize that can be used to exclude additional space.

Parameters:

  • context: The BuildContext used to access the screen width.
  • height: The height of each grid item.
  • width: The width of each grid item.
  • logData: (Optional) Set to true to log the calculated aspect ratio.
  • discardSize: (Optional) An additional size to be excluded from the width calculation.

Returns the calculated childAspectRatio as a double.

Implementation

double cGetResGridRatio({
  required BuildContext context,
  required int height,
  required int width,
  bool logData = false,
  double? discardSize,
}) {
  double primaryWidth = ((context.cWidth) - (discardSize ?? 0.0));
  double w = (primaryWidth / (primaryWidth / width).round());
  double h = (primaryWidth / (primaryWidth / width));
  double asr = w / (h - (width - height));
  if (logData) {
    cLog('GridAspectRatio => $asr');
  }
  return asr;
}