getLayout method
Returns information about the size and position of the tiles in the grid.
Implementation
@override
SliverGridLayout getLayout(SliverConstraints constraints) {
final double usableCrossAxisExtent =
constraints.crossAxisExtent - crossAxisSpacing * (crossAxisCount - 1);
final double tileWidth = usableCrossAxisExtent / crossAxisCount;
final double tileHeight = smallCellExtent;
if (bigCellExtent - smallCellExtent == 0) {
return SliverGridRegularTileLayout(
crossAxisCount: crossAxisCount,
mainAxisStride: tileHeight + mainAxisSpacing,
crossAxisStride: tileWidth + crossAxisSpacing,
childMainAxisExtent: tileHeight,
childCrossAxisExtent: tileWidth,
reverseCrossAxis:
axisDirectionIsReversed(constraints.crossAxisDirection),
);
} else if (isFirstCellBig) {
return _XSliverGridLayout1(
crossAxisCount: crossAxisCount,
crossAxisExtent: tileWidth,
crossAxisStride: tileWidth + crossAxisSpacing,
smallChildMainAxisExtent: smallCellExtent,
bigChildMainAxisExtent: bigCellExtent,
smallChildMainAxisStride: smallCellExtent + mainAxisSpacing,
bigChildMainAxisStride: bigCellExtent + mainAxisSpacing,
isFirstCellBig: isFirstCellBig,
);
} else {
return _XSliverGridLayout2(
crossAxisCount: crossAxisCount,
crossAxisExtent: tileWidth,
crossAxisStride: tileWidth + crossAxisSpacing,
smallChildMainAxisExtent: smallCellExtent,
bigChildMainAxisExtent: bigCellExtent,
smallChildMainAxisStride: smallCellExtent + mainAxisSpacing,
bigChildMainAxisStride: bigCellExtent + mainAxisSpacing,
isFirstCellBig: isFirstCellBig,
);
}
}