Dart Builder

Getting Started

The most common scenario is creating a new generated file in a transformer or build step. Dart builder provides the SourceFile class to output either a library or a part file (of another library):

var file = new SourceFile.library('bar');
file.toSource(); // Outputs "library bar;\n"

It's possible to import other libraries or files:

new SourceFile.library('bar', imports: [
  new ImportDirective(Uri.parse('package:foo/foo.dart'))
]);

And include other dart constructs, like classes or methods:

new SourceFile.library('bar', topLevelElements: [
  new ClassRef('Foo')
]);

NOTE: By default, SourceFile.toSource() applies the dart formatter.

Creating a class

new ClassRef('Foo', fields: [
  new FieldRef('bar')
], methods: [
  new MethodRef('baz')
]);

See tests for more examples.

Libraries

dart_builder