isWrappedInSemanticsWithLabel function
Check if the IconButton is wrapped in a Semantics widget with a label
Implementation
bool isWrappedInSemanticsWithLabel(InstanceCreationExpression node) {
// Walk up the AST to find parent widget
AstNode? parent = node.parent;
while (parent != null) {
if (parent is NamedExpression && parent.name.label.name == 'child') {
// Check if the parent is a Semantics widget
final grandParent = parent.parent?.parent;
if (grandParent is InstanceCreationExpression) {
final parentType = grandParent.staticType?.element?.name;
if (parentType == 'Semantics') {
// Check if Semantics has a label
for (final arg in grandParent.argumentList.arguments) {
if (arg is NamedExpression &&
arg.name.label.name == 'label' &&
hasNonEmptyStringValue(arg.expression)) {
return true;
}
}
}
}
break;
}
parent = parent.parent;
}
return false;
}