| |

Dart 101 ๐ŸŽฏ Cheatsheet

โฑ๏ธ 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

ExpressionResult
null is Objectfalse
null is Object?true
1 is numtrue
1.0 is intfalse
List<int> is List<num>true (covariant)
List<num> is List<int>false

Null-Aware Operators

OpMeaning
?.Null-aware access
??Null-coalescing
??=Assign if null
!Null assertion

Variables

KeywordReassignableImmutabilityTiming
varYesโ€”Inferred
finalNoRuntimeDeferred ok
constNoCompile-timeMust be const
late finalNoRuntimeFirst access

Falsy-like Values

Dart has no truthiness โ€” only bool in conditions.

Valueif (x) valid
true / falseYes
0, "", nullNo (compile error)

Functions

FeatureSyntax
Required positionalf(int a)
Optional positionalf(int a, [int b = 0])
Namedf({int a = 0})
Required namedf({required int a})
Arrowint f(int x) => x * 2
Tear-offfinal g = print
Typedeftypedef F = int Function(int)

Collections

Literals

LiteralType
[1, 2]List<int>
{1, 2}Set<int>
{'a': 1}Map<String, int>
<int>[]List<int>
{<String, int>{}}Map<String, int>

List Methods

MethodMutatesReturns
addYesvoid
insertYesvoid
removeYesbool
sortYesvoid
where / mapNoIterable
reduce / foldNoValue
firstWhereNoT or throws
sublistNoList
toListNoList

Spread & Control Flow in Collections

PatternExample
Spread[...a, ...b]
Null-aware spread[...?maybeList]
If-element[if (x) a]
For-element[for (var x in xs) x * 2]

Classes & OOP

ConceptSyntax
ConstructorFoo(this.x)
Named ctorFoo.named()
Factoryfactory Foo() => ...
Const ctorconst Foo(this.x)
Initializer listFoo(int x) : _x = x
Getterint get x => _x
Setterset x(int v) => _x = v
Mixinmixin M {} + with M
Extensionextension E on String {}
Sealedsealed class S {}
Abstractabstract class A {}

Access

ModifierScope
_nameLibrary-private
@protectedSubclass + library
@privateLibrary only (annotation)

Async / Isolates

Futures & Streams

ConstructPurpose
Future<T>Single async value
Stream<T>Sequence of values
asyncReturns Future<T>
awaitSuspend until settled
async* / yieldReturns Stream<T>
await forIterate a Stream

Combinators

MethodBehavior
Future.waitAll resolve; any reject โ†’ reject
Future.anyFirst to complete
Future.delayedDelayed future
CompleterManual completion

Isolates

ConceptDetail
MemoryIndependent per isolate
CommMessage passing only
Isolate.spawnCreate isolate
Isolate.runSpawn + return result
TransferableTypedDataZero-copy transfer
dart:isolate on WasmNot available

VM Internals โ€” Object Layout

ComponentDetail
tags_ fieldGC bits + canonical bit + class ID
Class ID width16 bits (concrete classes)
Class tablePer-isolate array โ†’ Class metadata
Smi tagLow bit = 0
Heap object tagLow bit = 1
Smi range (64-bit)โˆ’2โถยฒ to 2โถยฒโˆ’1
Smi range (32-bit)โˆ’2ยณโฐ to 2ยณโฐโˆ’1

Smi vs Heap Number

AspectSmiHeap Number
AllocatesNoYes
GC-trackedNoYes
Write barrierEliminatedRequired
RangeTagged bitsFull 64-bit

VM Internals โ€” Inline Caches

IC States

StateDispatchTrigger
UnlinkedResolution stubFirst execution
MonomorphicClass check + jumpOne receiver class
PolymorphicLinear scan of ICData2..N classes
MegamorphicHash lookupExceeds threshold

ICData Format

FieldPurpose
numArgsCheckedArguments checked
Class-target pairsDispatch groups
TerminatorEnd marker

Reload & Debug

EventEffect
Hot reloadResets mono/mega โ†’ poly/unlinked
Debugger steppingResets mono/mega โ†’ poly/unlinked

VM Internals โ€” GC & Safepoints

Space & Collector

SpaceCollectorAlgorithm
NewScavengerCopying (semispaces)
OldMark-sweepMark + sweep (concurrent)

Allocation Path

ConditionAction
Fits in TLABBump allocate
Larger than TLABOld space
TLAB fullNew buffer, GC if needed
Still failsOld space

Thread States

StateAt Safepoint
kThreadInGeneratedNo
kThreadInVMNo
kThreadInNativeYes
kThreadInBlockedStateYes

Write Barrier

BarrierConditionAction
GenerationalOld container + new valueAdd to remembered set
IncrementalOld unmarked value + markingAdd to worklist

Barrier Elimination

CaseEliminated
ConstantYes
SmiYes
Self-referenceYes
Fresh alloc, no GCYes

Safepoint Levels

LevelRequirements
GCStackmaps
DeoptStackmaps + deopt-id
ReloadStackmaps + deopt-id + reload

Compilation Targets

TargetCommandOutputRuntime
JITdart runIn-memoryVM
AOTdart compile exeNative binaryNone (bundled)
JSdart compile js.jsBrowser JS
Wasmdart compile wasm.wasm + .mjsWasmGC

dart2js vs dart2wasm

Aspectdart2jsdart2wasm
BackendSSA โ†’ JSWasmGC
GCBrowser JSWasmGC
OutputSingle .js.wasm + loader
Null/undefinedDistinctCollapsed
Browser req.Any JSWasmGC (Chrome 137+)

AOT Snapshot Format

SectionContentsDeserialization
DataStrings, metadata, typesClustered, deserialized
CodeMachine codeMapped directly
Instructions tablePC โ†’ stack mapBaked into rodata

Async/Await Desugaring

SourceState Machine
async functionClass with moveNext
_stateExecution position
CompleterReturned Future
awaitRegister callback, return
ResumptionCallback calls moveNext
try/catch across await_pendingError re-thrown in try
Local variablesCopied to SuspendState on suspend

Toolchain

CommandPurpose
dart run main.dartJIT execute
dart compile exeNative binary
dart compile jsJavaScript
dart compile wasmWebAssembly
dart analyzeStatic analysis
dart format .Format code
dart testRun tests
dart pub getResolve deps
dart fix --applyApply fixes
dart doc .Generate docs

pubspec.yaml Essentials

SectionPurpose
namePackage name
versionSemver
environment.sdkSDK constraint
dependenciesRuntime deps
dev_dependenciesDev-time deps
executablesCLI 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

BaseSizeShellHEALTHCHECK
scratch~15 MBNoOrchestrator only
alpine~20 MBYesPossible
debian:bookworm-slim~90 MBYesYes

Gotchas

TrapReality
typeof null"object" in JS; Dart has no typeof โ€” use is
NaN == NaNfalse; use isNaN
Integer division/ returns double; use ~/ for int
final listList is immutable reference; contents mutable
const listContents are immutable
String interpolation'$x' vs ${x + 1}
Cascade with ?obj?..a()?..b()
late final re-initThrows LateInitializationError
dynamic castsNo static check; runtime failure
Isolate sharingMust transfer, not share

Quick Decision Tables

var vs final vs const

Use whenโ€ฆKeyword
Value reassignedvar
Value never reassigned, runtimefinal
Value never reassigned, compile-timeconst
Init deferred, never reassignedlate final

List vs Set vs Map

NeedUse
Ordered, indexed, duplicatesList
Unique valuesSet
Key-valueMap

Future vs Stream

NeedUse
Single async resultFuture
Multiple async resultsStream
BothStream<T>.first / Future<T>

Isolate vs Async

NeedUse
I/O boundasync/await
CPU boundIsolate
Shared mutable stateNeither (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)

Was this helpful?


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!