findPrimaryControlDescendant function

Element? findPrimaryControlDescendant(
  1. Element element
)

Nearest primary-control descendant, if any.

Prefers specific controls (switch, dropdown, icon, …) over generic GestureDetector/InkWell wrappers that often wrap them.

Implementation

Element? findPrimaryControlDescendant(Element element) {
  Element? specific;
  Element? generic;
  void visit(Element e) {
    if (isPrimaryControlElement(e)) {
      if (_isGenericTapTarget(e.widget)) {
        generic ??= e;
      } else {
        specific ??= e;
      }
      return;
    }
    e.visitChildren(visit);
  }

  element.visitChildren(visit);
  return specific ?? generic;
}