@Deprecated annotation is a built-in metadata marker in Dart used to identify declarations (classes, functions, variables, or parameters) that are obsolete and slated for future removal. Applying this annotation instructs the Dart analyzer to emit a static warning (deprecated_member_use) whenever the marked element is referenced. While it does not alter the executable instructions or runtime behavior of the code, the metadata is preserved during compilation into the Dart Kernel.
Dart provides two forms of this annotation, both defined in the dart:core library:
1. Parameterized @Deprecated (Preferred)
This form invokes the Deprecated class constructor, accepting a single positional String argument. The string is surfaced directly in the IDE or compiler warnings, providing developers with migration instructions or versioning details.
@deprecated (Legacy)
This is a lowercased, unparameterized constant instance of the Deprecated class, defined internally as const Deprecated("next release"). It provides a generic warning without specific migration guidance.
Technical Characteristics
- Target Scope: The annotation can be applied to almost any Dart declaration, including
class,mixin,extension,typedef,method,getter,setter,variable, andparameter. - Compilation and AST: During parsing, the annotation modifies the Abstract Syntax Tree (AST) by adding an
Annotationnode to the targeted declaration. This metadata is retained in the compiled Dart Kernel (.dillfiles) and can be accessed programmatically via reflection (dart:mirrors) or macro builders. - Inheritance Behavior: Deprecation is not strictly transitive. Overriding a
@Deprecatedmethod in a subclass does not automatically apply the@Deprecatedmetadata to the subclass’s method, though the analyzer will flag the override itself as a usage of a deprecated member. - Linting: The Dart linter enforces the use of the parameterized version over the unparameterized constant via the
provide_deprecation_messagelint rule.
Tired of Poor Dart Skills? Fix That With Deep Grasping!Learn More





