hasParentTooltip function

bool hasParentTooltip(
  1. InstanceCreationExpression node
)

Check if a widget has a parent with a tooltip parameter

Implementation

bool hasParentTooltip(InstanceCreationExpression node) {
  // Walk up the AST to find parent widget
  AstNode? current = node.parent;

  while (current != null) {
    if (current is NamedExpression && current.name.label.name == 'child') {
      // Check if the parent is a Tooltip widget or has a tooltip parameter
      final grandParent = current.parent?.parent;
      if (grandParent is InstanceCreationExpression) {
        final parentType = grandParent.staticType?.element?.name;

        // Check if parent is a Tooltip widget
        if (parentType == 'Tooltip') {
          return true;
        }

        // Check if parent widget has a tooltip parameter
        for (final arg in grandParent.argumentList.arguments) {
          if (arg is NamedExpression && arg.name.label.name == 'tooltip') {
            if (hasNonEmptyStringValue(arg.expression)) {
              return true;
            }
          }
        }
      }
      // Continue searching up the tree instead of breaking
    }
    current = current.parent;
  }

  return false;
}