super_annotations
0.12.0, released 8 days ago by schultek.dev
Generate Dart code using custom annotations defined alongside your source files.
What it does
Provides base annotation classes and a @CodeGen() library annotation to run custom code‑generation logic during build_runner builds. Developers implement apply() to emit classes, extensions, mixins, etc., into generated .g.dart (or other) files.
AI-written summary of version 0.12.0, based on the package's README and metadata. Report an inaccuracy
Use it when
- You need custom code generation without writing a separate builder package
- You want to define annotations and generation logic in the same project
- You prefer a simple setup with build_runner
Skip it when
- You only need standard JSON/serialization code (use json_annotation)
- You require runtime reflection instead of build‑time generation
Strengths
- Minimal boilerplate to start generating code
- Supports multiple generation targets and hooks
- Leverages code_builder for correctly formatted output
Weaknesses
- Limited to build_runner ecosystem
- No runtime code‑gen support
- Requires familiarity with code_builder API
Setup
- Kind
- Pure Dart
- Effort
- Low
- Code generation
- Yes (build_runner)
- Direct dependencies
- 6
Add super_annotations as a dependency and build_runner as a dev_dependency, then annotate libraries with @CodeGen() and run pub run build_runner build
import 'package:super_annotations/super_annotations.dart';
@CodeGen()
library example;
@MyAnnotation()
class MyClass {
MyClass(this.value);
final String value;
}
class MyAnnotation extends ClassAnnotation {
const MyAnnotation();
@override
void apply(Class target, LibraryBuilder output) {
output.body.add(Code('// generated code'));
}
}
Alternatives
Packages that do the same job and could replace super_annotations.
- freezed_annotation
Offers code generation for immutable data classes and unions, with built‑in support in build_runner
78Compare
Works with
Packages commonly used together with super_annotations: ones it builds on, ones built on it, and its own family.
- analyzersuper_annotations depends on itPerforms static analysis of Dart code for tool integration and embedding.
- dart_stylesuper_annotations depends on itProvides an API and CLI to format Dart source code automatically.
- code_buildersuper_annotations depends on itA fluent, builder-based library for generating valid Dart code programmatically.
- buildsuper_annotations depends on itPackage for authoring build_runner compatible code generators.
- source_gensuper_annotations depends on itSource code generation builders and utilities for the Dart build system.
- build_runnerUsed togetherA build system for Dart code generation and modular compilation.