Page 21 - Dart Language
P. 21
Chapter 5: Comments
Syntax
• // Single-line comment
• /* Multi-line/In-line comment */
• /// Dartdoc comment
Remarks
It is good practice to add comments to your code to explain why something is done or to explain
what something does. This helps any future readers of your code to more easily understand your
code.
Related topic(s) not on StackOverflow:
• Effective Dart: Documentation
Examples
End of Line Comment
Everything to the right of // in the same line is commented.
int i = 0; // Commented out text
Multi-Line Comment
Everything between /* and */ is commented.
void main() {
for (int i = 0; i < 5; i++) {
/* This is commented, and
will not affect code */
print('hello ${i + 1}');
}
}
Documentation using Dartdoc
Using a doc comment instead of a regular comment enables dartdoc to find it and generate
documentation for it.
/// The number of characters in this chunk when unsplit.
int get length => ...
https://riptutorial.com/ 16

