loading

Dart Data Types

The most crucial and essential elements of a programming language are its data types. In Dart, a variable’s value determines its data type. Values are stored in the variables, and the memory location is reserved. What kind of value the variable will store is indicated by the data-type. A variable’s data type is unique to it. The variables in Dart cannot change because it is a static language.

Note: Dart is a static typing language that types annotations. Type annotations are optional, as Dart has the ability to infer types.

The following built-in Data types are supported by Dart.

  • Number
  • Strings
  • Boolean
  • Lists
  • Maps
  • Runes
  • Symbols

Dart Number

The numerical values are stored in the Darts Number. There are two possible sorts of numbers: double and integer.

  • Integer – Whole numbers or non-fractional values are represented by integer values. Numbers between -263 and 263 that are 64-bit non-decimal are represented by an integer data type. An unsigned or signed integer value can be stored in a variable. The following is the example:
				
					int marks = 80;  
				
			

Double – Double values, or numbers with huge decimal points, indicate 64 bits of information (double-precision). The double type variable is declared with the double keyword.

				
					double pi = 3.14;  
				
			

Dart Strings

A string is a character’s arrangement. Should we keep information such as name, location, distinctive character, etc. Either single quotations or double quotes are used to indicate it. A string of UTF-16 characters is called a dart string.

				
					var msg = "Welcome to JavaTpoint";  
				
			

Dart Boolean

The two values, true and false, are represented by the Boolean type. To indicate Boolean Type, use the bool keyword. The true or false value cannot be represented by the numbers 1 or 0.

				
					bool isValid = true;   
				
			

Dart Lists

A list in Dart is an assortment of ordered objects, or values. An array and a list share similar concepts. A collection of the various items contained in a single variable is called an array. The comma enclosed in the square bracket[] separates each entry in the list. The list of samples is provided below.

				
					var list = [1,2,3]  
				
			

Dart Maps

Values are stored as key-value pairs in the maps type. Every key has a value assigned to it. Any kind of value and key may be used. A value in a map can occur more than once, but the key needs to be distinct. Curly braces ({}) are used to define the Map, and a comma is used to separate each pair.

				
					var student = {'name': 'Joseph',  'age':25, 'Branch': 'Computer Science'}  
				
			

Dart Runes

As far as we are aware, the strings are a Unicode UTF-16 code unit sequence. A method called Unicode is used to specify a distinct numerical value for every letter, symbol, and digit. Since Unicode UTF-32 units’ special string is called a dart rune. It serves as a representation of the unique syntax.

As an illustration, the unique heart symbol ♥ is equal to Unicode code \u2665, where \u stands for Unicode and the values are hexadecimal integers. The hex value is enclosed in a curly bracket ({}) if it has fewer or more digits than four. For instance, \u{1f600} represents the emoji 😀. Here is an example of it.

				
					void main(){  
    var heart_symbol = '\u2665';  
    var laugh_symbol = '\u{1f600}';  
    print(heart_symbol);  
    print(laugh_symbol);  
}  
				
			

Output:

♥
😀

Dart Symbols

The objects that are used to refer to an operator or identifier that is declared in a Dart program are known as Dart symbols. Since identifier names can change but identifier symbols cannot, it is frequently used in APIs that refer to identifiers by name.

Dart Dynamic Type

The language Dart can be typed optionally. Dynamic variables are those in which the kind of variable is not expressly stated. For type annotation, the dynamic keyword is explicitly used.

Share this Doc

Dart Data Types

Or copy link

Explore Topic