removeChild method

  1. @override
void removeChild(
  1. RenderBox child
)
override

Remove the given child from the child list.

Called by RenderSliverVariableSizeBoxAdaptor.collectGarbage, which itself is called from RenderSliverVariableSizeBoxAdaptor.performLayout.

The index of the given child can be obtained using the RenderSliverVariableSizeBoxAdaptor.indexOf method, which reads it from the SliverVariableSizeBoxAdaptorParentData.startIndex field of the child's RenderObject.parentData.

Implementation

@override
void removeChild(RenderBox child) {
  final int index = renderObject.indexOf(child);
  assert(_currentlyUpdatingChildIndex == null);
  assert(index >= 0);
  owner?.buildScope(this, () {
    assert(_childElements.containsKey(index));
    try {
      _currentlyUpdatingChildIndex = index;
      final Element? result = updateChild(_childElements[index], null, index);
      assert(result == null);
    } finally {
      _currentlyUpdatingChildIndex = null;
    }
    _childElements.remove(index);
    assert(!_childElements.containsKey(index));
  });
}