Skip to content
Related Articles
Dart – Data Types
• Difficulty Level : Basic
• Last Updated : 14 Jul, 2020

Like other languages (C, C++, Java), whenever a variable is created, each variable has an associated data type. In Dart language, there is the type of values that can be represented and manipulated in a programming language. The data type classification is as given below:

1. Number: The number in Dart Programming is the data type that is used to hold the numeric value. Dart numbers can be classified as:

• The int data type is used to represent whole numbers.
• The double data type is used to represent 64-bit floating-point numbers.
• The num type is an inherited data type of the int and double types.

## Dart

 `void` `main() {``   ` `   ``// declare an integer``   ``int` `num1 = 2;             ``      ` `   ``// declare a double value``   ``double` `num2 = 1.5;  `` ` `   ``// print the values``   ``print(num1);``   ``print(num2);``   ``var a1 = num.parse(``"1"``);  ``   ``var b1 = num.parse(``"2.34"``);  ``    ` `   ``var c1 = a1+b1;   ``   ``print(``"Product = \${c1}"``); ``}`

Output:

```2
1.5
Product = 3.34
```

2. String: It used to represent a sequence of characters. It is a sequence of UTF-16 code units. The keyword string is used to represent string literals. String values are embedded in either single or double-quotes.

## Dart

 `void` `main() {``   ` `    ``String string = ``'Geeks'``'for'``'Geeks'``; ``    ``String str = ``'Coding is '``; ``    ``String str1 = ``'Fun'``; ``    ``print (string);  ``    ``print (str + str1);``}`

Output:

```GeeksforGeeks
Coding is Fun
```

3. Boolean: It represents Boolean values true and false. The keyword bool is used to represent a Boolean literal in DART.

## Dart

 `void` `main() {``  ``String str = ``'Coding is '``; ``  ``String str1 = ``'Fun'``; ``   ` `  ``bool` `val = (str==str1);``  ``print (val);  ``}`

Output:

```false
```

4. List: List data type is similar to arrays in other programming languages. A list is used to represent a collection of objects. It is an ordered group of objects.

## Dart

 `void` `main() ``{ ``    ``List gfg = ``new` `List(3); ``    ``gfg = ``'Geeks'``; ``    ``gfg = ``'For'``; ``    ``gfg = ``'Geeks'``; ``   ` `    ``print(gfg); ``    ``print(gfg); ``} `

Output:

```[Geeks, For, Geeks]
Geeks
```

5. Map: The Map object is a key and value pair. Keys and values on a map may be of any type. It is a dynamic collection.

## Dart

 `void` `main() { ``  ``Map gfg = ``new` `Map(); ``  ``gfg[``'First'``] = ``'Geeks'``; ``  ``gfg[``'Second'``] = ``'For'``; ``  ``gfg[``'Third'``] = ``'Geeks'``;``  ``print(gfg); ``}  `

Output:

```{First: Geeks, Second: For, Third: Geeks}
```

Note: If the type of a variable is not specified, the variable’s type is dynamic. The dynamic keyword is used as a type annotation explicitly.

My Personal Notes arrow_drop_up