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 Features

Dart is a fully-featured, object-oriented modern language with its roots in the programming language ‘Smalltalk’. It has some of its eminent features similar to the languages such as Java, C# and JavaScript. 

Some of its prominent features are : 

1. Open-Source : Dart is an open-source programming language developed by Google. Open-Source means that it is easily accessible and modifiable to the public. Dart is a BSD licensed, and Ecma approved programming language.

2. String Interpolation : Dart provides ways of converting expressions to strings either by using toString( ) inbuilt function or string interpolation method. String Interpolation uses $ or ${ } expression enclosed within single or double-quotes. For example, to convert the expression "hey" to a string, we can use $hey. Multiline strings can be created using three double-quotes.

For example, 

var name = "This" "is" "Dart". 

Space after "This" and "is" is intentionally left to add spaces between the words while printing them. 

The result would be : 

"This is Dart". 

Note that there is no '+' operator to concatenate two strings. 

3. Optional Type System : Unlike other languages, Dart provides the feature of optional typing, meaning that it is optional to mention the data type. Optional type annotations are used in variables definition, function parameters definition and return types and class definitions.

For example,

var a = "This is a Dart tutorial"
String b = "This is a Dart tutorial"

No type annotation is provided in the first example, while in the 2nd example, the data type String is mentioned. Dart can be considered as documentary typed language because the code runs the same with or without types. 

4. Traditional class-based structure : Dart uses classes and interfaces inspired by object-oriented concepts similar to those of Java and C# but not JavaScript. It supports single inheritance and multiple interfaces.

An important point to note is that all the classes in Dart inherit from the Object class by default. They have public and private members and getter and setter functions to use fields interchangeably with properties without affecting users of the class. Private members are indicated by prefixing the variable or method with ‘_’ (underscore) character. This makes it instantaneous to detect the scope. 

‘this’ keyword refers to a specific instance of the class and not the owner of the class at any instant, like in JavaScript. 

Another important point to remember is that the classes are optional in Dart, and this means that functions can be declared even if they don't belong to any class. Functions can exist in top-level scope if they are not the part of any class. 

5. Implied interface definitions : Dart has a powerful feature of implementing a class that doesn't have an explicit interface. It mocks a class or provides custom implementation of a class, making it optional to inherit from a shared base class explicitly. Ideally, all classes define an implicit interface on their public members.

6. Factory constructors for default implementations : At times, it is required to use a single implementation of an interface under most circumstances. Dart supports this feature using the concept of factory constructors. The programmer defines a base class as an interface and supplies a factory constructor to provide a default concrete instance of the class.

7. Libraries and scope : Dart breaks up a source code into different modules stored in separate files. A library is a collection of all those files that make up a whole single file. In Dart, a library is one or more. Dart files are grouped together in a logical manner. Each file can have none or many classes and top-level functions. A particular library can import other libraries that its source code uses. Source files can reference the code of other source files from the same library or imported libraries.

A library can be declared or defined using a library keyword. Other libraries can be imported using the import keyword, and other source files are referred to using part keyword. 

A library can contain any number of source files, including 0. 

8. Functions as first-class objects : Functions are regarded as first-class citizens because they are capable of performing all the functions available to Objects. Dart allows you to pass functions as objects, store a function in a variable, pass a function as a parameter and anonymous functions to use as call backs.

9. Concurrency with isolates : Dart is a single-threaded language with a simple model to code in.

Isolates are the unit of work in Dart with their own memory allocation that establishes an isolated security model. Memory sharing is not allowed among isolates, but messages can be communicated. Each code runs its own isolate in a web page. Dart enables the code to spawn a new isolate from the running code. Isolates are also used to load the code dynamically outside the application's core code that is loaded into their own memory protected space. 

Whenever a message is passed within an isolate, the receiver isolate receives a copy of the message from the sending isolate. Any changes to the received data aren't automatically reflected on the sender's site. Therefore, another message reflecting the changes has to be sent back to the sending isolate. 

The Dart Virtual Machine implementation sometimes use multiple cores to run isolates as per the requirements. 

10. Platform Independent : Dart is a platform-independent programming language which means it can be run on any operating system like Windows, Linux. This feature is enabled through Dart Virtual Machines that can provide support to run the code in any programming language. 

11. Browser Support : Dart is compatible with all modern browsers. The Dart2js compiler converts the Dart source code into JavaScipt code, making it suitable for any web browser. 

These are some of the major features of the Dart language. It supports additional extensive utilities such as interfaces, mixins, abstract classes, reified generics, and type inference which will be discussed later in the tutorial.