cGetGridRatio function
Calculate the childAspectRatio
for a GridView based on item dimensions and crossAxisCount
.
This function calculates the childAspectRatio for a GridView based on the
provided height
, width
, and crossAxisCount
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.crossAxisCount
: The number of items in the cross-axis of the GridView.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 cGetGridRatio({
required BuildContext context,
required int crossAxisCount,
required int height,
required int width,
bool logData = false,
double? discardSize,
}) {
double primaryWidth = ((context.cWidth) - (discardSize ?? 0.0));
double w = (primaryWidth / crossAxisCount);
double h = (primaryWidth / (primaryWidth / width));
double asr = w / (h - (width - height));
if (logData) {
cLog('GridAspectRatio => $asr');
}
return asr;
}