Skip to content
AddHunt
VS Code extensions

dmx

Dart code generation on save, with no part files

Open source

  • Open source
  • Licence: BSD-3-Clause

In short

dmx is an open-source Dart code generator that rewrites annotated classes whenever a file is saved, adding members such as copyWith, equality and JSON handling directly into the class. It is for Dart and Flutter developers who want to drop build_runner runs and .g.dart files, and it works through a VS Code extension.

What you get

  • Regenerates Dart code on every save
  • Writes members into the class, no .g.dart files
  • Validates the full file before writing
  • 11 built-in macros
  • Editable Mustache templates and custom Dart macros
  • Browser playground with no install

The details

dmx takes a different route to Dart code generation. Instead of producing separate part files that a build step has to refresh, it writes generated members straight into the annotated class, between two //#region markers. There is no part directive, no .g.dart file and no build_runner command to remember.

Generation on save

The VS Code extension starts a watcher when the workspace opens. Saving a file whose generated output has changed rewrites it, and files with unchanged output are left alone. Before anything is written, dmx parses the complete candidate file; if generation fails, the original stays exactly as it was.

Built-ins, templates and macros

The current release ships 11 built-in macros covering models, unions, enums, routes, REST clients and SQL tables. The model macro, for example, produces immutable classes with JSON conversion, copyWith, equality, hashCode and toString, and individual parts can be switched off.

  • The built-ins render through Mustache templates that a team can edit to match its conventions
  • Custom Dart macros can walk a parsed class and return the code to emit
  • A sample project macro reads a SQLite database and creates a row class for each table or view

All three paths share the same validation and atomic write. A browser playground allows trying dmx without installing anything, and the code is BSD-3-Clause licensed.

Alternatives to dmx

Questions

Does dmx need build_runner?

No. Generation happens on save through the VS Code extension's watcher, without a build_runner run or generated part files.

What happens if generation fails?

dmx checks the whole candidate file before writing. If it does not validate, the file is left unchanged.

Can teams change the generated code?

Yes. The built-in macros render through Mustache templates that can be edited, and custom Dart macros can generate code the built-ins do not cover.

More like this