unused_element
The declaration '{0}' isn't referenced.
Description
#The analyzer produces this diagnostic when a private declaration isn't referenced in the library that contains the declaration. The following kinds of declarations are analyzed:
- Private top-level declarations and all of their members
- Private members of public declarations
Not all references to an element will mark it as "used":
- Assigning a value to a top-level variable (with a standard
=
assignment, or a null-aware??=
assignment) does not count as using it. - Referring to an element in a doc comment reference does not count as using it.
- Referring to a class, mixin, or enum on the right side of an
is
expression does not count as using it.
Example
#Assuming that no code in the library references _C
, the following code
produces this diagnostic:
dart
class _C {}
Common fixes
#If the declaration isn't needed, then remove it.
除非另有说明,文档之所提及适用于 Dart 3.7.3 版本,本页面最后更新时间: 2025-05-08。 查看文档源码 或者 报告页面问题。