Skip to main content

Command Palette

Search for a command to run...

Comments in Dart/Flutter

Updated
•2 min read•View as Markdown
Comments in Dart/Flutter

The comments are notes that developers can add in source code and are ignored by compilers. It's an art of describing what your code does and maybe why. These comments are not evaluated.

It increases the code readability for other developers as well as the self that allows providing information of what tricky things are done within the code for better understanding and maintenance.

In this article, we will look into different types of comments supported by Dart.

The comments in Dart can be done in following different ways:

  • Single-line comments //
  • Multi-line comments /* ... */
  • Single-line Doc comments ///
  • Multi-line Doc comments /** ... */

Single-line comments in Dart

Single line comment can be done by // i.e double slash or double forward slash.

// this is a single-line comment

Multi-line comments in Dart

Multi-line comment also known as block comment. It can be done by /* ... */.

/*
  this is a multi-line comment
  we can also wrap code that is quite useful during debugging or development
*/

Dart guide suggests us to single-line comment //. The block comment (/* ... */) should only be used temporarily to comment out a section of code.

Single-line Doc comments in Dart

Doc comments parsed by dartdoc generates beautiful doc pages from them. A comment is any comment that appears before a declaration is called as a Doc comment.

Doc comments also support Markdown formatting

Single line Doc comment can be done by /// i.e triple-slash or triple forward slash.

You can find usage of it in dart:io library available on GitHub

/// this is a single-line comment

Multi-line Doc comments in Dart

Multi-line Doc comment can be done by `/ ... */`**. Below is an example of a multi-line Doc comment.

/**
  * ** Important:** Browser-based apps can't use this library.
  * Only the following can import and use the dart:io library:
  *   - Servers
  *   - Command-line scripts
  *   - Flutter mobile apps
  *   - Flutter desktop apps
  */

Read the complete post on our site Dart - Comments

Read others posts on our site MeshWorld

Hope you like this!

Keep helping and happy 😄 coding

L

Geometry Dash Lite - The controls are straightforward: tap to jump and hold to perform continuous jumps. Despite its simplicity, the game is known for its difficulty, requiring precise timing and quick reflexes.

S

This is one of the best posts I've read on this forum. The information in the article helped me understand more about a new topic that I had never known. slither io

L
Lee sara2y ago

This is a fantastically written and insightful article. This is, without a doubt, among the finest articles ever published. Your excellent performance inspires me to raise my own standards. Please know how much I appreciate it if you do. dordle game

C

These comments are ignored by the compiler and do not affect the code's functionality but can provide valuable information to other developers or future self who may work wordle on the same codebase.

M
mrshhair4y ago

I find the idea of ​​the waffle game very good and fresh. It will also suggest framed 2 me something for my work

W
win lizee4y ago

If you're not used to typesetting your wordle 2 code, this may take some getting used to. Compared to JavaScript, Dart also has stricter rules about variable names and lengths (if you don't follow the rules, you'll get a compile error). This makes it much harder to accidentally overwrite an existing variable or add an extra one accidentally (these kinds of bugs are known as "undefined variables" in JavaScript)

S

Dart is used to building all kinds of applications: web, server, and mobile (IOS and Android with Flutter engine). Dart is a language that supports object-oriented programming, C-style syntax, and Dart code that can be compiled into JavaSript to run in the browser. Sedecordle