Search code examples
flutterdartcomments

What is the difference between // and /// in flutter


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


Solution

  • 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 guides-documenting-dart-libraries. For the usage and examples refer guides-dartdoc