cGetResCrossCountGrid function

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

Calculate the responsive crossAxisCount for a GridView based on item width.

This function calculates the number of items that can fit in the cross-axis of a GridView based on the provided width. 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.
  • width: The width of each grid item.
  • logData: (Optional) Set to true to log the calculated count.
  • discardSize: (Optional) An additional size to be excluded from the width calculation.

Returns the calculated crossAxisCount as an integer.

Implementation

int cGetResCrossCountGrid({
  required BuildContext context,
  required int width,
  bool logData = false,
  double? discardSize,
}) {
  double primaryWidth = ((context.cWidth) - (discardSize ?? 0.0));
  int count = (primaryWidth / width).round();
  if (logData) {
    cLog('GridCount => $count');
  }
  return count;
}