Comments

Dart supports single-line comments, multi-line comments, anddocumentation comments.

Single-line comments

A single-line comment begins with //. Everything between // and theend of line is ignored by the Dart compiler.

  1. void main() {
  2. // TODO: refactor into an AbstractLlamaGreetingFactory?
  3. print('Welcome to my Llama farm!');
  4. }

Multi-line comments

A multi-line comment begins with / and ends with /. Everythingbetween / and / is ignored by the Dart compiler (unless thecomment is a documentation comment; see the next section). Multi-linecomments can nest.

  1. void main() {
  2. /*
  3. * This is a lot of work. Consider raising chickens.
  4. Llama larry = Llama();
  5. larry.feed();
  6. larry.exercise();
  7. larry.clean();
  8. */
  9. }

Documentation comments

Documentation comments are multi-line or single-line comments that beginwith /// or /**. Using /// on consecutive lines has the sameeffect as a multi-line doc comment.

Inside a documentation comment, the Dart compiler ignores all textunless it is enclosed in brackets. Using brackets, you can refer toclasses, methods, fields, top-level variables, functions, andparameters. The names in brackets are resolved in the lexical scope ofthe documented program element.

Here is an example of documentation comments with references to otherclasses and arguments:

  1. /// A domesticated South American camelid (Lama glama).
  2. ///
  3. /// Andean cultures have used llamas as meat and pack
  4. /// animals since pre-Hispanic times.
  5. class Llama {
  6. String name;
  7. /// Feeds your llama [Food].
  8. ///
  9. /// The typical llama eats one bale of hay per week.
  10. void feed(Food food) {
  11. // ...
  12. }
  13. /// Exercises your llama with an [activity] for
  14. /// [timeLimit] minutes.
  15. void exercise(Activity activity, int timeLimit) {
  16. // ...
  17. }
  18. }

In the generated documentation, [Food] becomes a link to the API docsfor the Food class.

To parse Dart code and generate HTML documentation, you can use the SDK’sdocumentation generation tool.For an example of generated documentation, see the Dart APIdocumentation. For advice on how to structureyour comments, seeGuidelines for Dart Doc Comments.