Menu
×
   ❮   
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP C C++ C# AWS W3.CSS HOW TO BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS DSA TYPESCRIPT ANGULAR ANGULARJS GIT POSTGRESQL SQLITE MONGODB ASP AI R GO KOTLIN SWIFT SASS VUE GEN AI SCIPY CYBERSECURITY DATA SCIENCE INTRO TO PROGRAMMING HTML & CSS BASH RUST DART PLAYWRIGHT TOOLS MATH SHEETS POWER BI

Dart Tutorial

Dart HOME Dart Intro Dart Get Started Dart Syntax Dart Output Dart Comments Dart Variables Dart final and const Dart Data Types Dart Numbers Dart Strings Dart String Interpolation Dart String Methods Dart Booleans Dart Type Conversion Dart Null Safety Dart late Dart Operators Dart Arithmetic Dart Assignment Dart Comparison Dart Logical Dart Type Test Dart Null Operators Dart Cascade Dart If...Else Dart Switch Dart While Loop Dart For Loop Dart Break/Continue

Dart Collections

Dart Lists Dart Access List Items Dart Change List Items Dart Loop Lists Dart List Methods Dart Sets Dart Maps Dart Access Map Items Dart Loop Maps Dart Collection if/for Dart Spread Operator

Dart Functions

Dart Functions Dart Parameters Dart Named Parameters Dart Return Values Dart Arrow Functions Dart Anonymous Functions Dart Closures Dart Scope Dart Recursion

Dart Classes

Dart OOP Dart Classes/Objects Dart Constructors Dart Named Constructors Dart Factory Constructors Dart Getters and Setters Dart Static Members Dart Inheritance Dart Abstract Classes Dart Interfaces Dart Mixins Dart Extension Methods Dart Enums Dart Generics

Dart 3 Features

Dart Records Dart Patterns Dart Switch Expressions Dart Sealed Classes Dart Class Modifiers

Dart Errors

Dart Exceptions Dart Custom Exceptions

Dart Async

Dart Async Intro Dart Futures Dart async/await Dart Streams Dart Isolates

Dart Libraries

Dart Imports Dart Packages Dart Math Dart Dates Dart JSON Dart RegExp Dart User Input Dart Files Dart Testing

Dart Examples

Dart Examples Dart Exercises


Dart Data Types


Share

Dart Data Types

Every value in Dart has a data type.

The data type decides what kind of value it is and what you can do with it.

For example, you can multiply two numbers, but you cannot multiply two names.

Example

void main() {
  int age = 30;
  double price = 9.99;
  String name = 'Emma';
  bool isMember = true;
  print(age);
  print(price);
  print(name);
  print(isMember);
}
Try it Yourself »

Result:

30
9.99
Emma
true

Built-in Data Types

This table shows the most important data types in Dart:

TypeDescriptionExample
intWhole numbers, without decimals25, -7
doubleNumbers with decimals3.14, -0.5
numAny number, an int or a double10, 10.5
StringText'Hello'
booltrue or falsetrue
ListAn ordered collection of values['Volvo', 'BMW']
SetA collection of unique values{'red', 'green'}
MapA collection of key and value pairs{'name': 'Emma', 'city': 'Oslo'}
RecordA small, fixed group of values('Emma', 30)
dynamicTurns off type checks, so the variable can hold any typedynamic x = 5;
ObjectAny value that is not nullObject x = 'Hi';

You will learn more about these types in later chapters.



Get the Type With runtimeType

You can find the type of any value with the runtimeType property:

Example

void main() {
  var a = 25;
  var b = 3.14;
  var c = 'Hello';
  var d = true;
  var e = ['Volvo', 'BMW'];
  print(a.runtimeType);
  print(b.runtimeType);
  print(c.runtimeType);
  print(d.runtimeType);
  print(e.runtimeType);
}
Try it Yourself »

Result:

int
double
String
bool
List<String>

The type List<String> means "a list of strings".

Note: Use runtimeType to learn and to find mistakes.

To check a type in a real program, use the is operator, which you will learn in the Type Test chapter.


Numbers, Text and Booleans

int and double are both numbers, and num can hold either of them:

Example

void main() {
  num distance = 10;
  print(distance);
  distance = 10.5;
  print(distance);
}
Try it Yourself »

Result:

10
10.5

Text is stored as a String, and a yes or no value is stored as a bool:

Example

void main() {
  String greeting = 'Good morning';
  bool isSunny = false;
  print(greeting);
  print(isSunny);
}
Try it Yourself »

Result:

Good morning
false

Read more in Numbers, Strings and Booleans.


Collections

A collection is a type that holds many values.

A List keeps values in order, a Set keeps only unique values, and a Map stores pairs of keys and values:

Example

void main() {
  var cars = ['Volvo', 'BMW', 'Ford'];
  var colors = {'red', 'green', 'red'};
  var person = {'name': 'Emma', 'city': 'Oslo'};
  print(cars);
  print(colors);
  print(person);
}
Try it Yourself »

Result:

[Volvo, BMW, Ford]
{red, green}
{name: Emma, city: Oslo}

Note that the set prints red only once.

Read more in Lists, Sets, Maps and Records.


dynamic and Object

A variable of type dynamic or Object can hold a value of any type:

Example

void main() {
  dynamic x = 5;
  print(x);
  x = 'Hello';
  print(x);

  Object y = 5;
  print(y);
  y = true;
  print(y);
}
Try it Yourself »

Result:

5
Hello
5
true

The difference is that Dart does not check what you do with a dynamic value.

A mistake with a dynamic value is only found when the program runs:

Example

void main() {
  dynamic x = 5;
  print('Start');
  print(x.toUpperCase());
}
Try it Yourself »

Result:

Start
Unhandled exception:
NoSuchMethodError: Class 'int' has no instance method 'toUpperCase'.
Receiver: 5
Tried calling: toUpperCase()

With Object, Dart finds the same mistake before the program runs:

Example

void main() {
  Object x = 5;
  print('Start');
  print(x.toUpperCase());
}
Try it Yourself »

Result:

main.dart:4:11: Error: The method 'toUpperCase' isn't defined for the type 'Object'.
 - 'Object' is from 'dart:core'.
Try correcting the name to the name of an existing method, or defining a method named 'toUpperCase'.
  print(x.toUpperCase());
          ^^^^^^^^^^^

Tip: Use a real type like int or String when you can.

Use dynamic only when you really do not know the type.



Free account

Track your progress

XP earned 0 Day streak 0 Spaces 0 League —

New

Learn in Adventure Mode W3Schools Adventure App

Coding fundamentals as bite-sized lessons and challenges.

×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
sales@w3schools.com

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
help@w3schools.com

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookies and privacy policy.

Copyright 1999-2026 by W3Schools. All Rights Reserved. W3Schools is Powered by W3.CSS.