Flutter - Understanding Dart data types

Dart is the programming language adopted for developing APPs using Flutter technology.

It may assume dynamic typing, supporting that a certain variable receives any value and its type changes accordingly. For this purpose the variable has to be declared using the keyword "var".

It may also use explicit data types when variables are declared expressing its type. Some of native data types are: int, double, num, String, bool, List and Map.

Below an example about how each of these data types could be utilized:

void main(){
//data types: Number (int, double, num),String, bool, List, Map.
print("=== INT ===");
int intNumber=1;
print(intNumber);

print("=== DOUBLE ===");
double doubleNumber=1.5;
print(doubleNumber);

print("=== NUM ===");
var number=3.2;
print(number);

print("=== String ===");
String stringValue="Rafael";
print(stringValue);

print("=== BOOL ===");
bool booleanValue=false;
print(booleanValue);

print("=== List ===");
var list = new List.filled(3, 0, growable: false);//(size, default, growable)
list[0] = 12;
list[1] = 13;
list[2] = 11;
print(list);

print("=== Map ===");
var map = { "firstName":"Rafael", "LastName":"Queiroz"};
print(map["firstName"]);

map = new Map();
map["programing_language"]="Dart";
print(map["programing_language"]);
}

You may watch a demonstration about how to use each of these data types in the video below:





Comments

Popular posts from this blog

JSON conversion: Built-in functions to convert a string in JSON format to a python object

Filter: Implementing map reduce with lambda functions (python)

JS – Mastering Browser Console: Creating a Dynamic Login Form with Declarative Programming