Dart: Types of Comments

·

1 min read

Types of comment

Single line Comments

Single line comments are very useful to describe quick snippets of code. Type // and type your comment above the code.

```dart
// Comments out this line!
print(hello);
```

Block Comments

But, what if we we want to comment multiple lines at once? That's where block comments come in;

```dart
/* var cat = "cat";
var dog = "dog";
print(cat == dog); */

notIgnored = "Dragon";
```

❗ Block comments are designed for commenting out code. If you're writing instructions, use single-line comments!

Doc Comments

In larger projects with more people, it's helpful to extract the comments you've written into documentation that can be read somewhere besides the code, like a website. Doing this manually would be annoying! So, Dart gives us a particular type of comment that will be recognized by a special comment extractor later. We can create these comments with three slashes ///

///This variable contains the greeting the program will give the user
String greeting = "Hello Programmer! I'm your trusty computer";

Learn Flutter where you code Visit sideguide.dev/courses/flutter