Answer
Overview
Dart is a statically typed language, meaning every variable has a type. Flutter/Dart supports a rich set of built-in data types.
Core Data Types
Numbers
dartint age = 25; // Whole numbers (64-bit signed) double price = 9.99; // Decimal numbers (64-bit floating point) num mixed = 3; // Either int or double mixed = 3.14; // ✅ num can hold both // Int operations print(10 ~/ 3); // 3 (integer division) print(10 % 3); // 1 (modulo) print(2.pow(8)); // Use dart:math: pow(2, 8) = 256
String
dartString name = 'Alice'; String greeting = "Hello, $name!"; // Interpolation String multiLine = ''' This is a multi-line string '''; // Common operations print(name.length); // 5 print(name.toUpperCase()); // ALICE print(name.contains('Ali')); // true print(name.substring(0, 3)); // Ali print(name.split('')); // [A, l, i, c, e]
Boolean
dartbool isActive = true; bool isLoggedIn = false; // Dart requires explicit booleans (no truthy/falsy like JS) if (isActive) print('Active'); // ✅ // if (1) print('truthy'); // ❌ Error in Dart
List (Array)
dartList<int> numbers = [1, 2, 3, 4, 5]; var fruits = ['apple', 'banana', 'cherry']; // Type inferred numbers.add(6); numbers.removeAt(0); print(numbers.length); print(numbers[0]); numbers.sort();
Map (Dictionary/HashMap)
dartMap<String, int> scores = {'Alice': 95, 'Bob': 87}; var config = {'theme': 'dark', 'fontSize': 14}; scores['Charlie'] = 91; print(scores['Alice']); // 95 print(scores.containsKey('Bob')); // true
Set
dartSet<String> tags = {'flutter', 'dart', 'mobile'}; tags.add('dart'); // Duplicate — ignored print(tags.length); // 3 print(tags.contains('flutter')); // true
Null
dartint? nullableAge = null; // Nullable with ? String? name = null; // Null-safe access print(name?.length); // null (no crash) print(name ?? 'Guest'); // Guest (default if null)
Dynamic & Object
dartdynamic anything = 42; anything = 'now a string'; // No type error Object obj = 42; obj = 'string'; // ✅ Object? can be null too
Type Summary
| Type | Example | Notes |
|---|---|---|
text | text | 64-bit integer |
text | text | 64-bit float |
text | text text | int or double |
text | text | UTF-16 |
text | text | Strictly boolean |
text | text | Ordered, indexed |
text | text | Key-value |
text | text | Unique elements |
text | Any | Runtime-typed |
text | text | Null type |