Skip to main content
The @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('Use newMethod() instead. Will be removed in v2.0.0.')
void oldMethod() {
  // Implementation
}
2. Constant @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.
@deprecated
String legacyVariable = 'data';

Technical Characteristics

  • Target Scope: The annotation can be applied to almost any Dart declaration, including class, mixin, extension, typedef, method, getter, setter, variable, and parameter.
  • Compilation and AST: During parsing, the annotation modifies the Abstract Syntax Tree (AST) by adding an Annotation node to the targeted declaration. This metadata is retained in the compiled Dart Kernel (.dill files) and can be accessed programmatically via reflection (dart:mirrors) or macro builders.
  • Inheritance Behavior: Deprecation is not strictly transitive. Overriding a @Deprecated method in a subclass does not automatically apply the @Deprecated metadata 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_message lint rule.
Tired of Poor Dart Skills? Fix That With Deep Grasping!Learn More