Dart Data type | Dart Tutorial

Dart Data type

Variables can store data of different types, and different data types can do different things.

Dart supports the following data types:

  • numbers
  • strings
  • booleans
  • lists (also known as arrays)
  • maps
  • runes (for expressing Unicode characters in a string)
  • symbols

Dart String

A string is a sequence of characters, You can use either single or double quotes to create a string:


1
2
3
Var h1="Hello World!";
Or
Var h2= ‘Hello World’;

A string can be any text inside quotes. You can use single or double quotes.

Dart Numbers

Numbers come in two forms:

  • int

An integer data type is a non-decimal number between -263 to 263 – 1.

Rules for integers:

  • An integer must have at least one digit
  • Integers are numbers without a decimal point
  • An integer can be either positive or negative
  • Integer values no larger than 64 bits, depending on the platform.

Example


1
int age = 14;
  • double

If a number includes a decimal, it is a double. 64-bit (double-precision) floating-point numbers, as specified by the IEEE 754 standard.


1
double pi = 3.14;

Dart Booleans

For Boolean values, Dart has a type named bool. A Dart Boolean allows two variables either 1 or 0 or true or false. Here 1 is for true and 0 is for false


1
2
3
4
5
6
7
8
void main() {
bool istrue = true;
bool isfalse = false;

print(istrue); // returns true
print(isflase); // returns false

}

Dart Lists

An array stores multiple values in one single variable.

In Dart, arrays are List objects, so most people just call them lists.

Dart list literals look like JavaScript array literals. Here’s a simple Dart list:


1
var list = [1, 2, 3];

Maps

In general, 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. Dart support for maps is provided by map literals and the Map type.

Here are a couple of simple Dart maps, created using map literals:


1
var gifts = {  // Key:    Value  'first': 'Apple',  'second': 'Book',  'fifth': 'golden rings'};

Symbols

A Symbol 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:


1
#radix#bar

Symbol literals are compile-time constants.

Related Post

Java If-else Statement Java If-else Statement The Java if statement is used to test the condition. It checks boolean condition: true or false. For example, if a number i...
Drag and Drop Table View cell in IOS 11 & swi... Drag and Drop Table View cell in IOS 11 & swift 4
Control Flow Statements | Swift tutorial Control Flow : Swift tutorial Swift Provides diffrent type of controll flow statements like: Loops Statements : Loops are used for perform the t...
New features in XCode 10 Supported Configurations Xcode 10 beta requires a Mac running macOS 10.13.4 or later Xcode 10 beta includes SDKs for iOS 12, watchOS 5, macOS ...
UIPopOverPresentationController In Swift UIPopOverPresentationController UIPopOverViewController in swift is writen in swift 3.1 and Use the xcode Version 8.3.2. For use this import the Pop...
How to install flutter | Flutter tutorial Flutter is the google’s mobile app SDK for develop the high-quality native app for iOS and android. We can develop the app by use of DART and javascri...

Leave a Reply

Your email address will not be published. Required fields are marked *

Get more stuff like this
in your inbox

Subscribe to our mailing list and get interesting stuff and updates to your email inbox.