Dart – Data Types

1 0
Read Time:2 Minute, 43 Second

Dart – Data Types

In Dart language, there is the type of values that can be represented and manipulated in a programming language. Dart is a statically typed programming language. This means that variables always have a specific type and that type cannot change

Dart has the following built-in data types –

  • Numbers
  • Strings
  • Boolean
  • Lists
  • Maps
  • Runes
  • Symbols

Dart – Numbers

The number data type is used to hold numeric values. Dart supports the following numerical data types –

  • Integer
  • Double

Integer:

 Integers are used to store whole numbers. An integer data type is used to represent 64-bit non-decimal numbers between -263 to 263 β€“ 1. Integer can be declared using int keywords.

int apple = 4;

Double:

Double is used to represent 64-bit (double-precision) floating-point numbers or numbers with larger decimal points. Double can be declared using the double keyword.

double pi = 3.14;

Dart – Strings

A string variable is used to hold a series or sequence of characters – letters, numbers, and special characters. In Dart, the string can be represented either using single quotes or double quotes. In Dart, strings can be declared using the String keyword.

String uselessText = 'Text in single quote';
String anotherUselessText = "Text in double quote";

Dart – Boolean

The Boolean data type is used to represent the values, which can be either True or False. Boolean can be declared using the bool keyword.

bool isLike = true;

Dart – List

The list data type is used to represent a collection of objects. The List data type in Dart is synonymous with the concept of an array in other programming languages. An array is used to hold multiple values in a single variable. A list variable is defined by having values separated by commas and enclosed within square brackets ([]).

var languages = ["Dart", "C#", "C++", "PHP","Java"];

Dart – Map

A map is an object that associates keys and values. Both keys and values can be any type of object. Each key occurs only once, but you can use the same value multiple times. The Map can be defined by using curly braces ({ }) and values can be assigned and accessed using square braces ([]).

var gifts = {
  // Key:    Value
  'first': 'partridge',
  'second': 'turtledoves',
  'fifth': 'golden rings'
};

Dart – Runes

A Dart string is a sequence of Unicode UTF-16 code units, 32-bit Unicode values within a string are represented using a special syntax. A rune is an integer representing a Unicode code point. For example, the heart character β€˜β™₯ is represented using the corresponding Unicode equivalent \u2665, here \u stands for Unicode and the numbers are hexadecimal, which is essentially an integer. If the hex digits are more or less than 4 digits, place the hex value in curly brackets ({ })

var heart = '\u2665';

print(heart);
Output: β™₯

Dart – Symbols

A Symbol an object represents an operator or identifier declared in a Dart program. You might never need to use symbols, but they’re invaluable for APIs that refer to identifiers by name because minification changes identifier names but not identifier symbols.

To get the symbol for an identifier, use a symbol literal, which is just # followed by the identifier:

#radix
#bar

In the next lesson, you will learn about Variables & Constant.

Happy
Happy
100 %
Sad
Sad
0 %
Excited
Excited
0 %
Sleepy
Sleepy
0 %
Angry
Angry
0 %
Surprise
Surprise
0 %

Average Rating

5 Star
0%
4 Star
0%
3 Star
0%
2 Star
0%
1 Star
0%

2 thoughts on “Dart – Data Types

Leave a Comment