removeChild method

void removeChild(
  1. Box child
)

Removes a specific child from this parent box.

If the child is not found, this method does nothing. Otherwise, the child is removed, its parent references are cleared, and layout is marked for update.

Implementation

void removeChild(Box child) {
  final index = _children.indexOf(child);
  if (index == -1) return;
  final newChildren = List<Box>.from(_children)..removeAt(index);
  _attachChildren(newChildren);
  child._parent = null;
  child.parentData.nextSibling = null;
  child.parentData.previousSibling = null;
  markNeedsLayout();
}