In this chapter, we will learn about different Data Types that are available in dart.
Dart Data Types
Different data types are available in dart. For example,
String name = ‘Phil’; int number = 22;
Here,
‘Phil’ is string data. 22 is integer data.
Dart has the following data types:
Data Types | Description | Keyword |
Strings | Sequence of textual characters | String |
Numbers | Integer or floating point number | int, double, num |
Booleans | Values true and false | bool |
Lists | set of objects | List |
Maps | Set of value of key/value pairs | Map |
Dart Strings
String refers to the collection of characters. In dart, strings are enclosed in either single quotes or double quotes. The keyword String is used to represent string value.
For example,
String name = ‘Phil’; String name = ‘Lauren’;
Dart Numbers
Numbers represent integer values and floating values. For integer values, keyword int is used. And for floating values, keyword double is used. The num keyword represents numbers in general.
For example,
int value1 = 35; double value2 = 35.89; num value3 = 35.89; num value4 = 35;
Dart Booleans
Boolean values represent true and false. The bool keyword is used to denote boolean values.
For example,
bool isValue = true; bool count = false;
Dart Lists
In dart, the list represents a collection of objects/values. We can create a list data type by enclosing the values in square braces. For example,
var numbers = [4, 8, 2.4, 5];
Another way to create a list is by passing the new keyword to the List object. For example,
List names = new List();
Dart Maps
In dart, maps denote a collection of data in key/value pairs. The key and value can be of any data type. We can create a map data type by enclosing the value in curly braces and separating each pair by comma. For example,
var person = {‘name’: ‘Phil’, ‘age’: 25, isMale: true}
Another way to create map data is by passing the new keyword to the Map object. For example,
Map person = new Map();
In map data types, keys must be unique.