getLayout method

  1. @override
SliverGridLayout getLayout(
  1. SliverConstraints constraints
)
override

Returns information about the size and position of the tiles in the grid.

Implementation

@override
SliverGridLayout getLayout(SliverConstraints constraints) {
  assert(_debugAssertIsValid(constraints.crossAxisExtent));
  int crossAxisCount = (constraints.crossAxisExtent / (maxCrossAxisExtent + crossAxisSpacing)).ceil();
  // Ensure a minimum count of 1, can be zero and result in an infinite extent
  // below when the window size is 0.
  crossAxisCount = math.max(1, crossAxisCount);
  final double usableCrossAxisExtent = math.max(
    0.0,
    constraints.crossAxisExtent - crossAxisSpacing * (crossAxisCount - 1),
  );
  final double childCrossAxisExtent = usableCrossAxisExtent / crossAxisCount;
  final double childMainAxisExtent = mainAxisExtent ?? childCrossAxisExtent / childAspectRatio;
  return SliverGridRegularTileLayout(
    crossAxisCount: crossAxisCount,
    mainAxisStride: childMainAxisExtent + mainAxisSpacing,
    crossAxisStride: childCrossAxisExtent + crossAxisSpacing,
    childMainAxisExtent: childMainAxisExtent,
    childCrossAxisExtent: childCrossAxisExtent,
    reverseCrossAxis: axisDirectionIsReversed(constraints.crossAxisDirection),
  );
}