cGetResGridRatio function
double
cGetResGridRatio({
- required BuildContext context,
- required int height,
- required int width,
- bool logData = false,
- 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 totrue
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;
}