createGrid method

Widget createGrid(
  1. List<StaggeredGridTile> tiles
)

Wraps tiles in a measurable StaggeredGrid for height tracking.

Uses QuiltKey for uniqueness and MeasureSize to update quiltHeights on layout, logging sizes in verbose mode. Essential for dynamic extent estimation in Carpet.

Implementation

Widget createGrid(List<StaggeredGridTile> tiles) {
  QuiltKey<T> key = QuiltKey<T>(tileFaucet, tiles);
  return MeasureSize(
      key: key,
      onChange: (size) {
        int index = quiltBuffer.indexWhere((q) =>
            q.key is QuiltKey<T> &&
            (q.key as QuiltKey<T>).value == key.value);

        if (index != -1) {
          quiltHeights[index] = size.height;
          verbose(
              "[CARPET] Quilt Sizes(${quiltHeights.where((h) => h > 0).length}k|${quiltHeights.where((u) => u <= 0).length}u|${unseenPastQuiltCount}g): <${averageQuiltHeight.round()} avg> [?${estimateCarpetExtent.format()} xt] ${quiltHeights.map((e) => e > 0 ? e.round().format() : "?")}");
        } else {
          warn("[CARPET] Failed to find quilt for key: $key");
        }
      },
      child: StaggeredGrid.count(
        crossAxisCount: style.carpetWidth,
        mainAxisSpacing: style.spacing,
        crossAxisSpacing: style.spacing,
        children: tiles,
      ));
}