skip to Main Content

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

4

Answers


  1. 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.

    Login or Signup to reply.
  2. 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

    Login or Signup to reply.
  3. // 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.

    Login or Signup to reply.
  4. Dart supports three kinds of comments:

    // Inline comments
    
    /*
    Blocks of comments. It's not convention to use block comments in Dart.
    */
    
    /// Documentation
    ///
    /// This is what you should use to document your classes.
    

    Also can give you a good hint

    // TODO: some words
    

    enter image description here

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search