nearestExclusiveKeyedWrapperId function

String? nearestExclusiveKeyedWrapperId(
  1. Element element, {
  2. Size? viewport,
  3. String? routeName,
})

Nearest keyed/Invokable ancestor that wraps only this element's lineage (no other keyed widgets under the same wrapper).

Never inherits isStructuralPageShell ancestors (route-named or ~full-viewport KeyedSubtree).

Implementation

String? nearestExclusiveKeyedWrapperId(
  Element element, {
  Size? viewport,
  String? routeName,
}) {
  String? found;
  element.visitAncestorElements((ancestor) {
    final id = readOwnedWidgetLocatorId(ancestor);
    if (id == null) return true;
    if (isStructuralPageShell(
      ancestor,
      id,
      viewport: viewport,
      routeName: routeName,
    )) {
      // Ensemble page shell — stop without inheriting.
      return false;
    }
    if (_keyedWrapperHasOtherKeyedDescendant(ancestor, element)) {
      // Section shell with sibling keyed widgets — stop without inheriting.
      return false;
    }
    found = id;
    return false;
  });
  return found;
}