talira

code_builder

A fluent, builder-based library for generating valid Dart code

open sourceBSD-3-Clausefree

code_builder is the Dart team's library for generating Dart source code from code: classes, methods, fields and other syntax are built with fluent builders and written out as valid Dart by a DartEmitter, usually formatted with dart_style. Code generators, such as builders run by build_runner, use it instead of concatenating strings. It lives in the dart-lang/tools mono-repo and is published on pub.dev by tools.dart.dev.

Problems it solves

  • generate Dart source files from my own code generator without string concatenation
  • write a build_runner builder that emits valid Dart classes
  • build Dart code as a syntax tree and print it as formatted source

Features

  • Generates valid Dart code from fluent builders
  • Classes, methods, fields and expressions as builder objects
  • DartEmitter writes the result as Dart source

Alternatives

The same job

These do what code_builder does.

  1. build_version Put your Dart package's version into your source code
  2. source_gen A framework for writing Dart code generators
  3. source_helper Utilities for generating Dart source code
  4. copy_with_extension Generates type-safe copyWith extensions for Dart classes
  5. json_serializable Generate JSON to and from code for annotated Dart classes

Compare code_builder with the top 3