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.
If the declaration is intended to be used, then add the code to use it.
Was this page's content helpful?
Thank you for your feedback!
Provide details Thank you for your feedback! Please let us know what we can do to improve.
Provide details Unless stated otherwise, the documentation on this site reflects Dart 3.8.1. Page last updated on 2025-05-08. View source or report an issue.