Metadata

Use metadata to give additional information about your code. A metadataannotation begins with the character @, followed by either a referenceto a compile-time constant (such as deprecated) or a call to aconstant constructor.

Two annotations are available to all Dart code: @deprecated and@override. For examples of using @override,see Extending a class.Here’s an example of using the @deprecatedannotation:

  1. class Television {
  2. /// _Deprecated: Use [turnOn] instead._
  3. @deprecated
  4. void activate() {
  5. turnOn();
  6. }
  7.  
  8. /// Turns the TV's power on.
  9. void turnOn() {...}
  10. }

You can define your own metadata annotations. Here’s an example ofdefining a @todo annotation that takes two arguments:

  1. library todo;
  2. class Todo {
  3. final String who;
  4. final String what;
  5. const Todo(this.who, this.what);
  6. }

And here’s an example of using that @todo annotation:

  1. import 'todo.dart';
  2. @Todo('seth', 'make this do something')
  3. void doSomething() {
  4. print('do something');
  5. }

Metadata can appear before a library, class, typedef, type parameter,constructor, factory, function, field, parameter, or variabledeclaration and before an import or export directive. You canretrieve metadata at runtime using reflection.