DEV Community

Sujith V S
Sujith V S

Posted on

Dart Data Types - Cheat Sheet

Image description

//String
String className = "Sujith";
print(className);

//int
int b = 32;
print(b);

//double - for floating point numbers.
double avgmark = 35.6;
print(avgmark);

//num - Supports both double and int
num mygf = 4.3;
print(mygf);

//bool
bool activeClass = true;
print(activeClass);

var - supports all type of data
var teacherName = true;
print(teacherName);

dynamic - supports all type of data
dynamic mytchr = true;

print(mytchr);

Difference between var and dynamic data type in dart.
dynamic: can change TYPE of the variable, & can change
VALUE of the variable later in code. var: can't change
TYPE of the variable, but can change the VALUE of the
variable later in code.

//List
List studentName = ["Abhiram", "Aneesh",
"Vibin","Sujith"];
print(studentName);

List testList = [0, 1, 2];
print(testList);

List dynamicList = ["Sujith", 56, 78.3];
print(dynamicList);

//Map - key value pairs
Map mapVariable = {
"name" : "Sujith",
"age" : 27,
"Marks" : 89.3,
"Pass" : true,
"class" : "Flutter"
};
print(mapVariable);

Top comments (0)