dartfmt

Use the dartfmt command to replace the whitespace in your program with formatting that follows Dart guidelines. This is the same formatting that you can get when using an IDE or editor that has Dart support.

Provide a list of files or directories to the dartfmt command. For example, here’s how to format all the Dart files under the current directory’s bin, lib, and test directories:

$ dartfmt -w bin lib test

If you don’t want to overwrite the files, omit the -w option. The resulting source code is displayed to standard output.

$ dartfmt bin/main.dart
import 'package:my_app/my_app.dart' as my_app;

main(List<String> arguments) {
  print('Hello world: ${my_app.calculate()}!');
}
$

For information on additional command-line options, use the --help flag or see the documentation for the dart_style package.

$ dartfmt --help