Data Types In Dart

Data Types In Dart

This article covers 5 major data types of Dart Programming

  • Like other languages (C, C++, Java), every time a variable is created, each variable has a related data type. In Dart language, there may be the kind of values that can be represented and manipulated in a programming language. The records type classification is as given beneath:

Data Types In Dart.png

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:
  1. The int data type is used to represent whole numbers.
  2. The double data type is used to represent 64-bit floating-point numbers.
  3. The num type is an inherited data type of the int and double types.
  • Example Code :
void main() 
{

  // declare an integer
  int num1 = 2;            

  // declare a double value
  double num2 = 1.5;

  // print the values
  print(num1);
  print(num2);

  // Declare num data type 
  var a1 = num.parse("1");
  var b1 = num.parse("2.34");

  // Sum of num data types
  var c1 = a1+b1;
  print("Sum = ${c1}");

}

2. String

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

  • Example Code :

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

3. Boolean

  • It represents Boolean values true and false. The keyword bool is used to represent a Boolean literal in Dart.
void main() {
String str = 'Coding is ';
String str1 = 'Fun';

bool val = (str==str1);
print (val);
}

4. 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.

  • Example Code :

void main() 
{
  Map dart = new Map();
  dart['First'] = 'Flutter';
  dart['Second'] = 'Uses';
  dart['Third'] = 'Dart';
  print(dart);
}

5. List

  • List data type in dart is very similar to lists in Python Programming. A list is used to represent a collection of objects. It is an ordered group of objects.

  • Example Code :

void main()
{
    List data = new List(3);
    data[0] = 'Python';
    data[1] = 'Java';
    data2] = 'Flutter';

    print(data);
    print(data[0]);
}