Skip to content
pubscout

super_annotations

0.12.0, released 8 days ago by schultek.dev

Generate Dart code using custom annotations defined alongside your source files.

WASM-ready
$ flutter pub add super_annotations
Source repository

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

Works with

Packages commonly used together with super_annotations: ones it builds on, ones built on it, and its own family.