Dart – Data Types

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: 

Data Type Keyword Description
Number int, double, num Numbers in Dart are used to represent numeric literals
Strings String Strings represent a sequence of characters
Booleans bool It represents Boolean values true and false
Lists List It is an ordered group of objects
Maps Map It represents a set of values as key-value pairs

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

filter_none

edit
close

play_arrow

link
brightness_4
code

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}"); 
}

chevron_right


 

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

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


 

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

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


 

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

filter_none

edit
close

play_arrow

link
brightness_4
code

void main() 
    List gfg = new List(3); 
    gfg[0] = 'Geeks'
    gfg[1] = 'For'
    gfg[2] = 'Geeks'
    
    print(gfg); 
    print(gfg[0]); 

chevron_right


 

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

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


 

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

Small things always make you to think big

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.