Dart Built-in Primitive Types Table
| Category | Type Identifier | Declaration / Literal Example | Brief Description |
|---|---|---|---|
| Numbers | int, double | int a = 10; double b = 3.14; | Two numeric subtypes: integers and double-precision floating points, both inherit from the parent type num |
| Strings | String | var str = "foxdevelop.com"; | Stores UTF-16 character sequences; supports string interpolation, multi-line text and raw strings |
| Booleans | bool | bool flag = true; | Only two valid values: true and false |
| Records | Record literal (v1, v2) | var record = (10, "test"); | Fixed-length composite type holding multiple values; supports destructuring assignment |
| Functions | Function | void fn() {} Function func = ()=>1; | First-class objects that can be assigned to variables, passed as arguments and returned from functions |
| Lists (Arrays) | List | var list = [1,2,3]; | Ordered collection allowing duplicate elements, equivalent to arrays in other languages |
| Sets | Set | var set = {1,2,3}; | Unordered collection with unique non-duplicate elements |
| Maps (Key-Value Pairs) | Map | var map = {"name":"Tom"}; | Key-value storage structure where all keys must be unique |
| Runes (Unicode Code Points) | Runes | Runes("\u{1f600}") | Low-level access to string Unicode code points; the official characters package is recommended as a replacement |
| Null | Null | Null n = null; | Holds only the null value; core top-level type under Dart’s null safety system |
Every variable in Dart is fundamentally an object (an instance of a class). You can quickly create instances using literals, or initialize them by calling their corresponding constructors.
'hello' is a string literal, true is a boolean literal; Map() creates a Map via its constructor.
Special Auxiliary Language Types
These are not core primitive built-in types, but they are reserved Dart keywords.
These types serve special roles including type system management, asynchronous operations and static type checking:
| Type | Purpose |
|---|---|
Object | The parent class of all Dart types except Null |
Enum | Base parent class for all enumerations |
Future / Stream | Built exclusively for asynchronous programming workflows |
Iterable | Used with for-in loops and synchronous generators |
Never | Marks expressions that never complete normal execution (commonly used for functions that always throw exceptions) |
dynamic | Disables static type checking; prefer Object / Object? instead |
void | Signifies no return value, most commonly used as a function return type |
1. Numbers
Parent supertype: num
The numeric system has two subclasses: int for integers and double for floating-point numbers, both extending num.
1.1 int (Integer)
Value ranges differ by platform (Dart also compiles to web, which uses JavaScript under the hood):
- Native platforms:
-2^63 ~ 2^63 - 1 - Web (JS backend):
-2^53 ~ 2^53 - 1
Integers contain no decimal points and support decimal and hexadecimal notation prefixed with 0x
Example
void main() {
// Decimal integer
var pageCount = 123;
// Hexadecimal value
var hex = 0xDEADBEEF;
// Underscore number separators (Dart 3.6+ for readability)
var million = 1_000_000;
var mac = 0x00_14_22_01_23_45;
print(pageCount);
print(hex);
print(million);
print(mac);
}Code language: PHP (php)
Output
123
3735928559
1000000
86469845829
1.2 double (Double-Precision Float)
Values include decimal points or scientific notation syntax
void main() {
var pi = 3.14; // Standard decimal float
var raid = 1.61e5; // Scientific notation = 1.61 * 10^5
var tiny = 0.000_000_000_02; // Underscore separators for decimals
print(pi);
print(raid);
print(tiny);
}Code language: PHP (php)
3.14
161000.0
2e-11Code language: CSS (css)
1.3 Parent Type num
Variables declared as num can store both int and double values interchangeably:
void main() {
num money = 5;
money += 2.5; // Automatically converted to double, money = 7.5
// Integers auto-convert to doubles when assigned
double zoom = 1;
print(money);
print(zoom);
}Code language: PHP (php)
Output
7.5
1.0Code language: CSS (css)
1.4 Cross-Type Conversion
void main() {
// String → int
var one = int.parse('123');
// String → double
var pi = double.parse('3.14');
// int / double → String
String intStr = 99.toString();
String pi2 = 3.14159.toStringAsFixed(2); // Round to 2 decimal places → "3.14"
print(one);
print(pi);
print(pi2);
}Code language: JavaScript (javascript)
Output
123
3.14
3.14Code language: CSS (css)
1.5 int Exclusive Bitwise Operators
Only integer values support bit shifting, bitwise AND/OR/XOR and bitwise NOT. See this guide for details: Dart Bitwise and shift operators – FoxDevelop
void main() {
print(3 << 1); // Left shift: 0011 <<1 → 0110
print(3 | 4); // Bitwise OR
print(3 & 4); // Bitwise AND
print(~3); // Bitwise NOT
}Code language: PHP (php)
6
7
0
-4
1.6 Numeric Compile-Time Constants
Pure numeric literals and arithmetic operations between constants can be marked with const
A compile-time constant is a value fully calculated during compilation (before the program runs). Its value never changes at runtime and requires no live computation, declared with the const modifier.
const msPerSec = 1000;
const waitSec = 5;
const waitMs = waitSec * msPerSec; // Compile-time constant expressionCode language: JavaScript (javascript)
const: Compile-time constant — the compiler evaluates the expression’s fixed value before program launch and embeds it directly in the compiled binary; the value is read directly at runtime with no calculation overhead.
final: Runtime constant — assigned once when the program executes and cannot be overwritten after initial assignment.
1.7 Built-in Math Methods
Core helper methods come built into num; import dart:math for advanced mathematical operations
Common methods: abs(), ceil(), floor(), round()
num n = -3.6;
print(n.abs()); // 3.6
print(n.ceil()); // -3
print(n.floor()); // -4Code language: PHP (php)
2. String
Stores a UTF-16 encoded character sequence for representing text. Strings can be wrapped in either single or double quotation marks.
2.1 Declaration Syntax: Single vs Double Quotes
var s1 = 'Single quote string';
var s2 = "Double quote string";
// Escape special characters with backslash
var s3 = 'It\'s ok';
var s4 = "It's ok"; // Mixing quote types removes escape requirements
Code language: JavaScript (javascript)
Certain characters carry special parsing meaning inside strings (such as double quotes ", newlines and backslashes \). Writing them raw breaks string syntax and triggers compiler errors.
The escape character \ disables the special behavior of reserved characters and renders invisible control symbols.
Hidden input characters like carriage returns and tab keys require escape sequences to display correctly. For example \t inserts a tab character — run the sample code below to see how it works.
print("name\tage\tcountry");
print("Jack\t18\tUSA");
print("Lucy\t20\tEgypt");Code language: PHP (php)
2.2 String Interpolation ${expression}
- Omit curly braces for simple variables:
$variable - Objects automatically invoke their
.toString()method for text conversion
void main() {
var word = "interpolation";
var str1 = "Dart has $word";
var str2 = "Uppercase: ${word.toUpperCase()}";
print(str2); // Output: Uppercase: INTERPOLATION
}Code language: JavaScript (javascript)
2.3 String Concatenation
- Adjacent string literals auto-concatenate, even across line breaks
- Concatenate using the
+operator
var s1 = "First line"
"Second line";
var s2 = "a" + "b";
assert(s1 == "First lineSecond line");
assert(s2 == "ab");Code language: JavaScript (javascript)
2.4 Multi-line Strings: Triple Quotes ”’ / “””
void main() {
var multi1 = '''
Multi
line
text
''';
var multi2 = """
Triple double quote multi-line
hello foxdevelop.com
""";
print(multi1);
print(multi2);
}Code language: PHP (php)
Multi
line
text
Triple double quote multi-line
hello foxdevelop.comCode language: CSS (css)
Single triple quotes allow unescaped double quotes inside, and triple double quotes support raw single quotes with no escape characters required:
2.5 Raw Strings r”” — Disables all escape sequence parsing
var raw = r"Newline escape \n will not be processed";
print(raw); // Prints literal \n as written
Code language: PHP (php)
2.6 Limitations for const Constant Strings
All content inside interpolations must be compile-time constants (numbers, booleans, const strings); regular variables and collections are not permitted
const num cNum = 10;
const bool cBool = true;
const String cStr = "const";
// Valid constant string interpolation
const valid = "$cNum $cBool $cStr";
var normalNum = 10;
// Invalid: interpolation references a non-constant variable
// const invalid = "$normalNum";
Code language: JavaScript (javascript)
3. bool Boolean Type
Only two possible instances: true and false, both compile-time constants
Dart enforces strict static typing: implicit truthy/falsy checks are not allowed; explicit comparisons are mandatory
void main() {
var emptyStr = "";
print(emptyStr.isEmpty); // Check for empty string
var zero = 0;
print(zero == 0); // Explicit zero comparison
var nil = null;
print(nil == null); // Check null values
var nan = 0 / 0;
print(nan.isNaN); // Detect Not-a-Number values
}Code language: PHP (php)
4. Runes & characters — Working with Unicode Text
- Runes: Legacy API to access raw Unicode code points inside strings
- Recommended alternative:
package:characters, which handles complete visual grapheme clusters (such as flag emojis)
Unicode Escape Syntax
- 4-digit hexadecimal codes:
\uXXXX - Larger multi-digit code points:
\u{hex-value}
var heart = "\u2665"; // ♥
var laugh = "\u{1f606}"; // 😆
Code language: JavaScript (javascript)
package:characters Example
import 'package:characters/characters.dart';
void main() {
var text = "Hi 🇩🇰";
print(text.characters.last); // Outputs the full Denmark flag emoji
}
Code language: JavaScript (javascript)
5. Symbol
Used for reflection and code obfuscation workflows. Literal syntax is #identifier, and all Symbols are compile-time constants
Symbols remain unchanged after code minification/obfuscation, making them ideal for dynamically referencing identifiers by name
#userName
#getData
Code language: CSS (css)
6. Null Type
Holds exactly one value: null. Under Dart null safety, Null exists as an independent top-level type compatible with all nullable type declarations.
String? name = null;
Null n = null;
Code language: JavaScript (javascript)