โฑ๏ธ Estimated read: 5 min
|
|
A quick-reference for the Dart language, VM internals, and toolchain. No prose โ just the facts.
Language Basics
Types & Null Safety
| Expression | Result |
|---|
null is Object | false |
null is Object? | true |
1 is num | true |
1.0 is int | false |
List<int> is List<num> | true (covariant) |
List<num> is List<int> | false |
Null-Aware Operators
| Op | Meaning |
|---|
?. | Null-aware access |
?? | Null-coalescing |
??= | Assign if null |
! | Null assertion |
Variables
| Keyword | Reassignable | Immutability | Timing |
|---|
var | Yes | โ | Inferred |
final | No | Runtime | Deferred ok |
const | No | Compile-time | Must be const |
late final | No | Runtime | First access |
Falsy-like Values
Dart has no truthiness โ only bool in conditions.
| Value | if (x) valid |
|---|
true / false | Yes |
0, "", null | No (compile error) |
Functions
| Feature | Syntax |
|---|
| Required positional | f(int a) |
| Optional positional | f(int a, [int b = 0]) |
| Named | f({int a = 0}) |
| Required named | f({required int a}) |
| Arrow | int f(int x) => x * 2 |
| Tear-off | final g = print |
| Typedef | typedef F = int Function(int) |
Collections
Literals
| Literal | Type |
|---|
[1, 2] | List<int> |
{1, 2} | Set<int> |
{'a': 1} | Map<String, int> |
<int>[] | List<int> |
{<String, int>{}} | Map<String, int> |
List Methods
| Method | Mutates | Returns |
|---|
add | Yes | void |
insert | Yes | void |
remove | Yes | bool |
sort | Yes | void |
where / map | No | Iterable |
reduce / fold | No | Value |
firstWhere | No | T or throws |
sublist | No | List |
toList | No | List |
Spread & Control Flow in Collections
| Pattern | Example |
|---|
| Spread | [...a, ...b] |
| Null-aware spread | [...?maybeList] |
| If-element | [if (x) a] |
| For-element | [for (var x in xs) x * 2] |
Classes & OOP
| Concept | Syntax |
|---|
| Constructor | Foo(this.x) |
| Named ctor | Foo.named() |
| Factory | factory Foo() => ... |
| Const ctor | const Foo(this.x) |
| Initializer list | Foo(int x) : _x = x |
| Getter | int get x => _x |
| Setter | set x(int v) => _x = v |
| Mixin | mixin M {} + with M |
| Extension | extension E on String {} |
| Sealed | sealed class S {} |
| Abstract | abstract class A {} |
Access
| Modifier | Scope |
|---|
_name | Library-private |
@protected | Subclass + library |
@private | Library only (annotation) |
Async / Isolates
Futures & Streams
| Construct | Purpose |
|---|
Future<T> | Single async value |
Stream<T> | Sequence of values |
async | Returns Future<T> |
await | Suspend until settled |
async* / yield | Returns Stream<T> |
await for | Iterate a Stream |
Combinators
| Method | Behavior |
|---|
Future.wait | All resolve; any reject โ reject |
Future.any | First to complete |
Future.delayed | Delayed future |
Completer | Manual completion |
Isolates
| Concept | Detail |
|---|
| Memory | Independent per isolate |
| Comm | Message passing only |
Isolate.spawn | Create isolate |
Isolate.run | Spawn + return result |
TransferableTypedData | Zero-copy transfer |
dart:isolate on Wasm | Not available |
VM Internals โ Object Layout
| Component | Detail |
|---|
tags_ field | GC bits + canonical bit + class ID |
| Class ID width | 16 bits (concrete classes) |
| Class table | Per-isolate array โ Class metadata |
| Smi tag | Low bit = 0 |
| Heap object tag | Low bit = 1 |
| Smi range (64-bit) | โ2โถยฒ to 2โถยฒโ1 |
| Smi range (32-bit) | โ2ยณโฐ to 2ยณโฐโ1 |
Smi vs Heap Number
| Aspect | Smi | Heap Number |
|---|
| Allocates | No | Yes |
| GC-tracked | No | Yes |
| Write barrier | Eliminated | Required |
| Range | Tagged bits | Full 64-bit |
VM Internals โ Inline Caches
IC States
| State | Dispatch | Trigger |
|---|
| Unlinked | Resolution stub | First execution |
| Monomorphic | Class check + jump | One receiver class |
| Polymorphic | Linear scan of ICData | 2..N classes |
| Megamorphic | Hash lookup | Exceeds threshold |
ICData Format
| Field | Purpose |
|---|
numArgsChecked | Arguments checked |
| Class-target pairs | Dispatch groups |
| Terminator | End marker |
Reload & Debug
| Event | Effect |
|---|
| Hot reload | Resets mono/mega โ poly/unlinked |
| Debugger stepping | Resets mono/mega โ poly/unlinked |
VM Internals โ GC & Safepoints
Space & Collector
| Space | Collector | Algorithm |
|---|
| New | Scavenger | Copying (semispaces) |
| Old | Mark-sweep | Mark + sweep (concurrent) |
Allocation Path
| Condition | Action |
|---|
| Fits in TLAB | Bump allocate |
| Larger than TLAB | Old space |
| TLAB full | New buffer, GC if needed |
| Still fails | Old space |
Thread States
| State | At Safepoint |
|---|
kThreadInGenerated | No |
kThreadInVM | No |
kThreadInNative | Yes |
kThreadInBlockedState | Yes |
Write Barrier
| Barrier | Condition | Action |
|---|
| Generational | Old container + new value | Add to remembered set |
| Incremental | Old unmarked value + marking | Add to worklist |
Barrier Elimination
| Case | Eliminated |
|---|
| Constant | Yes |
| Smi | Yes |
| Self-reference | Yes |
| Fresh alloc, no GC | Yes |
Safepoint Levels
| Level | Requirements |
|---|
| GC | Stackmaps |
| Deopt | Stackmaps + deopt-id |
| Reload | Stackmaps + deopt-id + reload |
Compilation Targets
| Target | Command | Output | Runtime |
|---|
| JIT | dart run | In-memory | VM |
| AOT | dart compile exe | Native binary | None (bundled) |
| JS | dart compile js | .js | Browser JS |
| Wasm | dart compile wasm | .wasm + .mjs | WasmGC |
dart2js vs dart2wasm
| Aspect | dart2js | dart2wasm |
|---|
| Backend | SSA โ JS | WasmGC |
| GC | Browser JS | WasmGC |
| Output | Single .js | .wasm + loader |
| Null/undefined | Distinct | Collapsed |
| Browser req. | Any JS | WasmGC (Chrome 137+) |
AOT Snapshot Format
| Section | Contents | Deserialization |
|---|
| Data | Strings, metadata, types | Clustered, deserialized |
| Code | Machine code | Mapped directly |
| Instructions table | PC โ stack map | Baked into rodata |
Async/Await Desugaring
| Source | State Machine |
|---|
async function | Class with moveNext |
_state | Execution position |
Completer | Returned Future |
await | Register callback, return |
| Resumption | Callback calls moveNext |
try/catch across await | _pendingError re-thrown in try |
| Local variables | Copied to SuspendState on suspend |
Toolchain
| Command | Purpose |
|---|
dart run main.dart | JIT execute |
dart compile exe | Native binary |
dart compile js | JavaScript |
dart compile wasm | WebAssembly |
dart analyze | Static analysis |
dart format . | Format code |
dart test | Run tests |
dart pub get | Resolve deps |
dart fix --apply | Apply fixes |
dart doc . | Generate docs |
pubspec.yaml Essentials
| Section | Purpose |
|---|
name | Package name |
version | Semver |
environment.sdk | SDK constraint |
dependencies | Runtime deps |
dev_dependencies | Dev-time deps |
executables | CLI binaries |
Docker / Deployment
Multi-stage Build
FROM dart:stable AS build
WORKDIR /app
COPY pubspec.* ./
RUN dart pub get
COPY . .
RUN dart compile exe bin/server.dart -o bin/server
FROM scratch
COPY --from=build /runtime/ /
COPY --from=build /app/bin/server /bin/
CMD ["/bin/server"]
Runtime Base Comparison
| Base | Size | Shell | HEALTHCHECK |
|---|
scratch | ~15 MB | No | Orchestrator only |
alpine | ~20 MB | Yes | Possible |
debian:bookworm-slim | ~90 MB | Yes | Yes |
Gotchas
| Trap | Reality |
|---|
typeof null | "object" in JS; Dart has no typeof โ use is |
NaN == NaN | false; use isNaN |
| Integer division | / returns double; use ~/ for int |
final list | List is immutable reference; contents mutable |
const list | Contents are immutable |
| String interpolation | '$x' vs ${x + 1} |
Cascade with ? | obj?..a()?..b() |
late final re-init | Throws LateInitializationError |
dynamic casts | No static check; runtime failure |
| Isolate sharing | Must transfer, not share |
Quick Decision Tables
var vs final vs const
| Use whenโฆ | Keyword |
|---|
| Value reassigned | var |
| Value never reassigned, runtime | final |
| Value never reassigned, compile-time | const |
| Init deferred, never reassigned | late final |
List vs Set vs Map
| Need | Use |
|---|
| Ordered, indexed, duplicates | List |
| Unique values | Set |
| Key-value | Map |
Future vs Stream
| Need | Use |
|---|
| Single async result | Future |
| Multiple async results | Stream |
| Both | Stream<T>.first / Future<T> |
Isolate vs Async
| Need | Use |
|---|
| I/O bound | async/await |
| CPU bound | Isolate |
| Shared mutable state | Neither (message passing) |
One-Page Flow: Everything Connected
SOURCE
โ
โโ dart run โโโโโโโโโโโโโโโบ JIT (dev, hot reload, profile)
โ
โโ dart compile exe โโโโโโโบ AOT native (fast startup)
โ โ
โ โโ Docker: scratch / debian-slim
โ โโ No SDK needed at runtime
โ
โโ dart compile js โโโโโโโโบ JS (any browser)
โ
โโ dart compile wasm โโโโโโบ WasmGC (modern browsers, dual build)
RUNTIME (VM)
โ
โโ Object header: tags_ (GC | canonical | class ID)
โโ Smi: encoded in pointer (low bit 0)
โโ Class table: class ID โ vtable, metadata
โโ IC: unlinked โ mono โ poly โ mega
โโ Alloc: TLAB bump โ scavenge โ promote โ mark-sweep โ sweep
โโ Async: state machine (moveNext, _state, Completer)
Stop using slow, ad-bloated tool sites! ๐คฎ
๐ Search “KandZ Tools” on Google to use many professional utilities for free.
KandZ.me is the ultimate minimalist hub for:
โ
Finance (Mortgage, Interest, Inflation)
โ
Tech (Base64, JSON, Dev Suite, IP)
โ
Health (BMI, BMR, TDEE)
โ
Productivity (Timer, Workspace, QR)
โก๏ธ Fast & Private
๐ No data leaves your device
๐ 100% Free
๐ Use it now: https://tools.kandz.me
๐ Bookmark itโyouโll need it later!