Home > database >  What is the difference between // and /// in flutter
What is the difference between // and /// in flutter

Time:01-26

I was just commenting my application as i found out that you can use diffrent commenting. I'am curious if there are some commenting rules for this or has it something to do with the auto commenting of flutter it self?

My choice go's to the /// one since the color is different so it is better to see what i commented and what flutter did.

This make me wonder why there are two diffrent ways to comment

//  <-- This is a way
/// <-- This is a way

enter image description here

Thanks in advance

CodePudding user response:

In Flutter, // is used to create a single-line comment, which is ignored by the Dart compiler.

/// is used to create a documentation comment, which can be used to generate documentation for your code using the dartdoc tool. This type of comment is also ignored by the Dart compiler, but it can be used to provide additional information about a class, function, or variable for developers reading the code.


Example:

/// This is a documentation comment for a function
void myFunction() {
  // this is a single-line comment
}

When you use dartdoc tool, it will extract the comments from the code and generates the documentation in HTML format.

In addition to this refer the official documentation about dartdoc enter image description here

CodePudding user response:

According to Effective Dart,

// is for a single-line comment, like you'd have on the inside of a function

/// is for multi-line (though single-lines are supported too) documentation comments, like you'd have above a function definition.

CodePudding user response:

// is for a single-line comment, like you'd have on the inside of a function

/// is for multi-line used to documentation comments, like you'd have above a function definition.

  • Related