dart_code 0.2.2 copy "dart_code: ^0.2.2" to clipboard
dart_code: ^0.2.2 copied to clipboard

A package for creating valid and formatted code, e.g. when writing code builders.

example/example.dart

import 'package:dart_code/dart_code.dart';

main() {
  /// A simple formatting example:
  print(DartFunction.main(Statement.print(Expression.ofString('Hello World.')))
      .toFormattedString());

  // OUTPUTS:
  // main() {
  //   print('Hello World.');
  // }

  /// An alternative formatting example
  print(DartFunction.main(Statement.print(Expression.ofString('Hello World.')))
      .toFormattedString(pageWidth: 20));

  // OUTPUTS:
  // main() {
  //   print(
  //     'Hello World.');
  // }

  /// An library example with imports
  print(Library(classes: [
    Class(
      'Employee',
      superClass: Type('Person', libraryUri: 'package:my_package/person.dart'),
      implements: [
        Type('Skills', libraryUri: 'package:my_package/skills.dart')
      ],
      abstract: true,
    )
  ]).toFormattedString());

  // OUTPUTS:
  // import 'package:my_package/person.dart' as i1;
  // import 'package:my_package/skills.dart' as i2;
  //
  // abstract class Employee extends i1.Person implements i2.Skills {}
}
4
likes
160
points
99
downloads

Publisher

unverified uploader

Weekly Downloads

A package for creating valid and formatted code, e.g. when writing code builders.

Repository (GitHub)

Topics

#code-generation #source-code #dart

Documentation

API reference

License

BSD-3-Clause (license)

Dependencies

dart_style

More

Packages that depend on dart_code