findChildByKey method

  1. @override
ChildLayout? findChildByKey(
  1. Object key
)
override

Finds a child element by its unique key.

Searches through children to find one with a matching debug key. Returns null if no child with the specified key is found.

Implementation

@override
ChildLayout? findChildByKey(Object key) {
  RenderBox? child = firstChild;
  while (child != null) {
    final childParentData = child.parentData as LayoutBoxParentData;
    if (childParentData.layoutData.key == key ||
        (childParentData.layoutData.key is ValueKey &&
            (childParentData.layoutData.key as ValueKey).value == key)) {
      return RenderBoxChildLayout(child, this);
    }
    child = childParentData.nextSibling;
  }
  return null;
}