Built-in Data Types in Dart Programming Language

Way of representing different data while programming are known as data types. This article explains built-in data types in dart programming language.

The Dart programming language has support for the following built-in types:

1. Numbers - Numeric Types in Dart

Numbers in dart are either integer number or floating point number. Two numeric data types in dart are: int & double. Both int and double are subtypes of class num.

int Data Type

int represents integer data types and consist integer values no larger than 64 bits, depending on the platform.

Integers are numbers without a decimal or floating point. Some examples of defining integer literals are:

int Examples

int number = 67;
var hexnumber = 0xFF;

double Data Type

double represents 64-bit double-precision floating-point numbers.

All number that includes a decimal point are double number. Some examples of defining double literals are:

double Examples

double rate = 15.5;
var ex = 4.12e3;

Here ex = 4.12e3 is exponent form representation which is equivalent to 4120.

2. Strings - Character Type in Dart

A string is collection of characters. In dart string is a sequence of unicode UTF-16 code units.

Type name String is used to represent dart string.

In dart, single or double quotes are used to represent string.

string Examples

String name = "Alex";
var address = "Alabama";

3. Booleans

Boolean types has only two values i.e. true or false.

Type name bool is used to represent Boolean types.

bool Examples

bool isValid = true;
var isOk = false;

4. Lists

Array, or ordered group of objects in Dart is Lists. Dart list literals are similar to JavaScript array literals i.e. [ ]. Some examples of dart lists are:

List Examples

var numbers = [34,56,-89,7.8];
var names = ["Jack", "Alice","Alex"];

5. Sets

Unordered collection of unique items in Dart is Sets. In Dart, Set literals uses { }. Some examples of dart sets are:

Set Example

var names = {'Jack','Alex','Alice','John'};

6. Maps

Key value pairs in Dart are Maps. Maps uses { } literals with key and value. Key occurs only once but value can occur multiple times. Examples of Maps are:

Map Example

var john = {
  'name': 'John',
  'age': 23,
  'sex':'Male',
  'address':'Alabama'
};