diff --git a/lib/src/analyzers/unused_code_analyzer/used_code_visitor.dart b/lib/src/analyzers/unused_code_analyzer/used_code_visitor.dart index 0138a1493..a3e0fc092 100644 --- a/lib/src/analyzers/unused_code_analyzer/used_code_visitor.dart +++ b/lib/src/analyzers/unused_code_analyzer/used_code_visitor.dart @@ -97,6 +97,9 @@ class UsedCodeVisitor extends RecursiveAstVisitor { @override void visitNamedType(NamedType node) { + if (_isUsedInWidgetStateClassDeclaration(node)) { + return; + } _recordPrefixedElement(node.importPrefix, node.element); super.visitNamedType(node); } @@ -244,4 +247,14 @@ class UsedCodeVisitor extends RecursiveAstVisitor { return grandGrandParent is NamedType && isWidgetStateOrSubclass(grandGrandParent.type); } + + bool _isUsedInWidgetStateClassDeclaration(NamedType namedType) { + final parent = namedType.parent; + if (parent is TypeArgumentList) { + final grandParent = parent.parent; + return grandParent is NamedType && + isWidgetStateOrSubclass(grandParent.type); + } + return false; + } }