removeChild method

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

Remove the given child from the child list.

Called by RenderSliverMultiBoxAdaptor.collectGarbage, which itself is called from RenderSliverMultiBoxAdaptor's performLayout.

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

Implementation

@override
void removeChild(RenderBox child) {
  if (child is RenderBoxModel) {
    SliverMultiBoxAdaptorParentData parentData = child.parentData as SliverMultiBoxAdaptorParentData;
    // The index of sliver list.
    int index = parentData.index!;

    Iterable<Node> renderNodes = _renderNodes;
    if (index < renderNodes.length) {
      renderNodes
          .elementAt(index)
          .unmountRenderObject(deep: true);
      return;
    }
  }

  // Fallback operation, remove child from sliver list.
  _sliverListLayout.remove(child);
}