Skip to main content
A multi-line comment (or block comment) in Dart is a lexical construct delimited by /* and */. The Dart compiler treats all characters enclosed within these delimiters as whitespace, effectively ignoring them during compilation. These comments can span across multiple lines of code or be embedded within a single line.

Syntax

The comment begins with a forward slash and an asterisk (/*) and terminates with an asterisk and a forward slash (*/).
/*
  This is a standard multi-line comment.
  The compiler ignores all text within this block.
  Variable declarations or logic placed here will not execute.
*/
void main() {
  print('Hello, World!');
}

Nested Comments

Unlike C or C++, Dart supports nested multi-line comments. The compiler tracks the depth of nesting, requiring a matching closing delimiter (*/) for every opening delimiter (/*) before the comment block is considered closed.
/*
  Level 1: Start of outer comment.
  /*
    Level 2: Start of nested comment.
    This text is still inside the comment block.
  */
  Level 1: End of outer comment.
*/

Inline Block Comments

Because the delimiters define precise start and end points, multi-line comments can be placed within a single line of code, between tokens.
void main() {
  // The comment is injected between the type and the variable name
  int /* comment */ x = 10; 
}
Master Dart with Deep Grasping Methodology!Learn More