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
- Built-in Annotations: override, deprecated
- Writing Custom Annotations
- Code Generation With build_runner
- json_serializable in Action