×

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( ) ;


Related Topics

Dart Objects

Apart from the built-in data types, Dart offers some other data types that have a special role to play. One of them is Objects.  Objects Objects are the foundation of the...

3 minutes read.

Rust vs Dart

Rust is a system-level programming language that stands next to C ++ in terms of syntax, but offers greater speed and memory security. Dart, on the other hand, is an...

2 minutes read.

Dart - extends, with and implements Keywords

The application development in Dart programming language using the Flutter framework, regularly experience different usage of the implements, extends and with keywords. Dart has full support for inheritance that is...

5 minutes read.

Dart Common Collection Methods

Most of the programming languages have arrays as a way to list items together. However, Dart has a collection of data structures similar to array. These are supported by the...

3 minutes read.

Builder Classes in Dart

Before understanding builder classes, let us understand about Flutter that makes the best use of the builder classes. Flutter is actually not a programming language, it is a software development...

6 minutes read.

Dart Break and Continue

Loop statements are used to change the normal sequence of flow of the program. Dart supports two types of loop control statements: Break StatementContinue Statement Break Statement : The ‘ break ’ statement is...

4 minutes read.

Dart super keyword

The ' super ' keyword is used to refer to the immediate parent class object of the currently in-use child class. Using this keyword, we can invoke the superclass (...

6 minutes read.

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...

2 minutes read.

Dart Miscellaneous Operators

Apart from the operators we studied so far, Dart provides some more operators which are as follows : Conditional OperatorCascade Notations Conditional Operators These are the operators that help in evaluating the expression...

1 minute read.

Dart Keywords

Keywords are the reserved words of a programming language, and they have a special meaning that comes defined by the language. These cannot be used as an identifier, and all...

1 minute read.

Dart Future and Stream

Before understanding Future and Stream in Dart, we need first to get familiar with two terms : Synchronous and Asynchronous Programming.  In synchronous programming, a single operation is handled at a...

9 minutes read.

Dart If-else-if statement

If - else - if statement enables to check the set of test expressions that evaluate to Boolean True or False, and based on this true or false the particular...

2 minutes read.

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: NeverDynamicVoid Let us understand each one in detail, Never...

3 minutes read.

Typedef in Dart

In Dart, typedef is used to generate a function type that we can use as a type annotation for declaring variables and return types of the function type. An alias...

4 minutes read.

Type System in Dart

Dart language is a type safety enabled language that uses static and dynamic type checking to match the value of the variable with its data type at the compile-time. This...

4 minutes read.

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#...

4 minutes read.

Callable Classes in Dart

Just like the functions, we can also call the instances of classes in Dart. Such classes are also known as “callable ” classes. We need to use the “call( )”...

3 minutes read.

Dart Bitwise and Shift Operators

The Bitwise operators are the operators that perform different operations bit by bit on the value of the two operands. List of Bitwise Operators in Dart Sr. Operators Description 1. & ( Binary AND ) It returns...

2 minutes read.

Dart URIs

The Uri class supports encoding and decoding of strings with the help of functions to be used in URIs ( which may also be known as URLs ). These functions...

6 minutes read.

Dart Packages

Every programming language has some in-built functions stored inside the header files that makes the task much easier for the programmer. The Dart Packages refer to the compilation of a...

4 minutes read.