0PricingLogin
Dart Academy · Lesson

Writing Custom Annotations

Attach metadata to your declarations.

Annotations Are Classes

A custom annotation is just an ordinary class. When you write @MyTag, you are referencing an instance of that class as metadata. 🏷️

Define the Class

Start by declaring a normal class to hold your metadata. Here a simple Todo annotation will later carry a message and an owner.

class Todo {
  final String message;
  const Todo(this.message);
}

All lessons in this course

  1. Built-in Annotations: override, deprecated
  2. Writing Custom Annotations
  3. Code Generation With build_runner
  4. json_serializable in Action
← Back to Dart Academy