Dart Cheat Sheet
Dart syntax, sound null safety, async programming, and collection methods used to build Flutter applications.
2 PagesIntermediateApr 8, 2026
Basic Syntax
Variables, control flow, and printing.
dart
void main() { int age = 30; var name = "Ada"; // type inferred as String const pi = 3.14159; bool isFun = true; if (age >= 18) { print("$name is an adult"); } for (int i = 0; i < 5; i++) { print("Count: $i"); }}
Null Safety
Sound null safety operators and late init.
dart
String? middleName; // nullable typemiddleName ??= "default"; // assign only if nullprint(middleName?.length); // safe navigationint? maybeAge;int age = maybeAge ?? 0; // null-coalescing operatorlate String description; // initialized before first usedescription = "computed later";
Async & Futures
Asynchronous programming with Future/async/await.
dart
Future<String> fetchData() async { await Future.delayed(Duration(seconds: 1)); return "data";}void main() async { print("Fetching..."); String result = await fetchData(); print(result); fetchData().then((value) => print(value)).catchError((e) => print(e));}
Collection Methods
Common Iterable/List operations.
- .map()- transforms each element, returns a lazy Iterable
- .where()- filters elements matching a predicate
- .reduce()- combines elements into a single value
- .toList() / .toSet()- materializes an Iterable into a concrete collection
- .firstWhere()- returns the first matching element or throws/orElse
- spread operator (...)- inlines one collection's elements into a list/set/map literal
Classes, Mixins & Inheritance
Object-oriented features including mixins.
dart
abstract class Shape { double area();}mixin Describable { String describe() => 'A shape with area $runtimeType';}class Circle extends Shape with Describable { final double r; Circle(this.r); @override double area() => 3.14159 * r * r;}void main() { final c = Circle(2); print(c.area()); // 12.566 print(c.describe());}
Streams & Async Iteration
Consuming and producing asynchronous streams.
dart
Stream<int> countTo(int n) async* { for (var i = 1; i <= n; i++) { await Future.delayed(Duration(milliseconds: 100)); yield i; }}Future<void> main() async { await for (final value in countTo(3)) { print(value); // 1, 2, 3 } final total = await countTo(3).fold(0, (a, b) => a + b); print(total); // 6}
Records & Pattern Matching
Dart 3 records and switch-based destructuring.
dart
// Records: lightweight anonymous tuples(String, int) getUser() => ('Ada', 36);final (name, age) = getUser();// Named fields({double lat, double lng}) pos = (lat: 1.0, lng: 2.0);// Switch expressions with patternsString classify(Object o) => switch (o) { int n when n > 0 => 'positive int', int _ => 'non-positive int', String s => 'string of length ${s.length}', _ => 'other',};
Keywords & Modifiers
Important declaration and class modifiers.
- late- defer non-null initialization until first access
- final- single-assignment variable set at runtime
- const- compile-time constant, canonicalized instances
- factory- constructor that may return a cached/subtype instance
- sealed- restrict subtypes for exhaustive switch checks
- extension- add methods to existing types without subclassing
- typedef- create an alias for a function or type
Pro Tip
Use the `late` keyword sparingly — it defers null-safety checks to runtime, so prefer nullable types with `??` when a default value is reasonable.
Was this cheat sheet helpful?
Explore Topics
#Dart#DartCheatSheet#Programming#Intermediate#BasicSyntax#NullSafety#AsyncFutures#CollectionMethods#Functions#DataStructures#Concurrency#CheatSheet#SkillVeris