performLayout method

  1. @override
Size performLayout(
  1. BoxConstraints constraints
)
override

Hook for subclasses to perform layout within the given constraints.

Implementation

@override
Size performLayout(BoxConstraints constraints) {
  final listView = widget as ListView;
  // Fallbacks to prevent 0,0 crashes while you debug the Column/Expanded constraints
  final width = constraints.hasBoundedWidth && constraints.maxWidth > 0
      ? constraints.maxWidth
      : 80;
  final height = constraints.hasBoundedHeight && constraints.maxHeight > 0
      ? constraints.maxHeight
      : listView.children.length;

  adjustScroll(height);

  visibleIndices = [];
  final childConstraints = BoxConstraints.tight(Size(width, 1));

  for (var i = 0; i < height; i++) {
    final itemIdx = scrollOffset + i;
    if (itemIdx >= childElements.length) break;

    final childElement = childElements[itemIdx];
    // 1. Tell the child how big it is
    childElement.layout(childConstraints);

    // Store the layout offset in the element!
    childElement.relativeOffset = Offset(0, i);

    visibleIndices.add(itemIdx);
  }

  return constraints.constrain(Size(width, height));
}