Dart Tutorial

Dart Tutorial Single-Page Application Architecture Dart Features Dart Installation Guide Dart Basic Program Dart Syntax Dart Keywords Dart Variables Dart Comments Dart Standard Input Output Dart Important Concepts

Data Types

Built-in Data Types Numbers Strings Booleans Lists Sets Maps Runes and Graphemes Symbols Enumerations Constants Queues

Other data types

Objects Future and stream Iterable Miscellaneous types

OPERATORS

Precedence and associativity Arithmetic operators Equality and Relational operators Type Test Operators Assignment Operators Logical Operators Bitwise and Shift Operators Miscellaneous operators

Control Flow Statements

Introduction If statement If-else statement If-else-if statement Loops Switch and case Dart Break And Continue Assert In Dart

FUNCTIONS

Dart function Types of Functions Anonymous function main( ) function Lexical scope and closure Recursion Common Collection Methods

Object Oriented Concepts

Dart Object-Oriented Concepts Dart Classes Dart Constructors Dart This Keyword Dart Super Keyword Static Members Method Overriding Dart Interfaces Inheritance Dart Abstract Classes Dart Builder Classes Dart Callable Classes

Dart Type System

Dart Type System Dart Soundness Dart Type Inference

MISCELLANEOUS

Dart Isolates Dart Typedef Dart Metadata Dart Packages Dart Generics Dart Generators Dart Concurrency Dart Unit Testing Dart Html Dom Dart URIs Dart Extends, With and Implements Keywords Dart Optional Parameters Rust Vs Dart C++ vs Dart Golang Vs Dart Dart Basics Exception Handling

Dart Comments

Comments are the statements that are used to enhance the readability and understandability of the code. The compiler does not execute these lines. It simply ignores these comments when it scans the code of compilation. It is a good practice to include comments in your code to refer them when you get back to your code. 

There are three types of comments in the Dart programming language:

  1. Single line comments
  2. Multi-line comments
  3. Documentation comments 

Single-line comments

A single-line comment is a comment that is only of a single line. It begins with ‘//’ and ends in a line.

Syntax:

// this is a single-line comment

Example:  

Consider the following code,

// This program depicts the concept of single-line comment 

void main( )

{

// print( 'This is the Flutter's tutorial’ );

     print( 'This is Dart tutorial' );

}

Output:

This is a Dart tutorial

As you can see, the compiler completely ignored the line “print( ‘This is a Flutter’s tutorial’)” because it is a comment, and printed the next line only. 

Multi-line comments

A multi-line comment is a comment that consists of multiple lines. It begins with ‘/*’ and ends with ‘*/’. Multi-line comments can be nested.  

Syntax: 

/* This is a 

Multi-line comment. */

Example: 

Consider the following code, 

// This program depicts the concept of multi-line comment 

void main( )

{

    var a = 4, b = 5, diff, mul;

    /* diff = a - b;

    mul = a * b; */

print( '\nThe value of a is $a \nThe value of b is $b \nThe value of diff is $diff \nThe value of mul is $mul' );

}

Output:

The value of a is 4

The value of b is 5

The value of diff is null

The value of mul is null

Since the lines assigning values to ‘diff’ and ‘mul’ are comment out, no value is assigned to these variables as the compiler simply ignored them. Therefore, null got printed, which is the default value assigned to the compiler in case no value is initialized. 

Documentation comments

Documentation comments are multi-line or single-line comments that begin with ‘///’ or ‘/**’. We can use ‘///’ in the consecutive lines which would work same as a multi-line comment. 

While analysing the code during compilation, the compiler ignores all the text except the text enclosed within the square bracket ‘[  ]’. These brackets are used as references to classes, methods, fields, functions, and parameters. 

Syntax:

/// This is 

/// a documentation

/// comment

Example:

Consider the following code,  

// This program depicts the concept of multi-line comment 

void main( )

{

    var a = 4, b = 5, diff, mul;

    /// diff = a - b;

    /// mul = a * b;

///print( '\nThe value of a is $a \nThe value of b is $b \nThe value of diff is $diff \nThe value of mul is $mul' );

    print( ' This shows documentation comment ' );

}

Output

This shows documentation comment