Author: Shailen Tuli Reviewers: Trevor Johns, Kathy Walrath
All sample code must comply with the official Dart Style Guide.
Use dartfmt to format your Dart code.
These guidelines are not required by the official Dart Style Guide, but must be followed in your Dart code. This includes samples (including snippets added to docs), larger apps, and libraries.
Imports should be ordered as follows, with each group ordered alphabetically. Leave a blank line after each group.
- dart: imports
- package: imports
- relative imports
For example:
import 'dart:async';
import 'dart:html';
import 'package:polymer/polymer.dart';
import 'src/header.dart';
import 'src/navbar.dart';
- Do not use block (
/** ... */
) comments. - Use
//
for comments. - Use
///
if you're showing a doc comment.
Defer to the Guidelines for Dart Doc Comments for how to format comment text.
Use the Pub package layout conventions to organize your files and directories.
When writing short samples, it is acceptable to
put all your files in web
(for web applications), bin
(for executables),
and lib
(for library code). You can also put samples in example
.
Add a library
declaration to each .dart
file. Prefix library names with the
package name and a dot-separated path. For example:
// In lib/foo/bar.dart
library my_package.foo.bar;
// In example/foo/bar.dart
library my_package.example.foo.bar;
See the Dart Style Guide for details.
Use the Dart unittest
package. Read the
Unit Testing with Dart
article for guidelines on how to use this package.