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 Miscellaneous types

Some Other Data types in Dart

Apart from the data types studied so far, we have three other data types also which are as follows:

  1. Never
  2. Dynamic
  3. Void

Let us understand each one in detail,

Never data type in Dart

Dart 2.9 offers a new bottom data type known as ‘Never’. Its declaration is there in the core libraries and can be used as a type annotation. It can act as a return type of functions. It has no values and using Never means that the expression can never successfully finish evaluating. It will either throw an exception or abort the execution of the code.

Remember that the static type of a throw expression is Never.

Example : Never fun( ) { }

Dynamic data type in Dart

This data type enables us to create variables that are dynamic in nature. By dynamic means their data type can be changed at the runtime.

For example,

                 dynamic msg = ‘ Hello World ! ’ ;

If instead of this, we have an initialization like this :

                 string msg = ‘ Hello World ! ’ ;

The compiler interprets that the variable ‘ msg ’ is of string type and will only and always hold string values. Even if we ever try to change its data type or to make it hold the integer value for example, we can’t do that.

Program

void main( )
{
      // initializing the string name
      String name = " This is dynamic data type tutorial ! " ;
      
      // printing the string name
      print( name ) ;
  
      // initializing the string type name with integer
      name = 8 ;   
}

Output

Some Other Data types in Dart

As you can see, the compiler threw a compilation error when we tried to assign the string variable ‘name’ with the integer value.

Consider another example where we use dynamic data type and tries to change the value of the variable:

Program

void main( )
{
      // initializing the string name
      dynamic name = " This is dynamic data type tutorial ! " ;
      
      // printing the string name
      print( name ) ;
  
      // initializing the string type name with integer
      name = 55 ;
  
      // printing the integer value of the dynamic variable name
      print( name ) ;
}

Output

This is dynamic data type tutorial !
55

void data type in Dart

void data type in programming languages usually means that they do not return anything. The return type in the Dart language only specifies what the DartAnlyzer warns us about.

If the return type of the function is void, it can return the following three

things :

1 ) Return null

2 ) Return dynamic variable

3 ) Return void function

Remember that we cannot use these returned values.

Constructors

  1. void ( )

Properties

1. hashCode

Returns the hash code for a numerical value, and it returns the same value for int and doubles when the value provided is the same. 

Implementation = external int get hashchode ;

2. runtimeType

Represents the type of runtime an object has. 

Implementation = Type get runtimeType ;

Methods

1. noSuchmethod ( )

This method is called when the non-existing method is accessed.

Implementation =

            dynamic noSuchMethod (

Invocation invocation

)

2. toString ( )

Converts a given number into an equivalent shortest string and returns the same. 

Implementation = external String toString( ) ;