Dart Cheatsheet - Dart Syntax & Flutter Reference

This reference is for Dart developers building Flutter apps or backend services, centered on the syntax you write all day: null-safe variables (final/const vs late), functions and closures, classes with mixins, and async flow with Future/async/await. Unlike a flat Dart feature list, entries are grouped by the construct and flag null-safety behavior that trips people new from Java/JS. After reading you should be able to write null-safe chains without non-null assertions everywhere, compose classes with mixins, and handle asynchronous work with Future and async/await without blocking the UI thread.

Languages·43 commands·Last updated 2026-07-21
dartflutterMobile Development

Variables & Types 10

var name = 'Dart';
Type inference
String name = 'Dart';
Explicit type
final name = 'Dart';
Final variable (runtime constant)
const pi = 3.14;
Compile-time constant
int? nullableInt;
Nullable type
late String lateVar;
Late initialization
dynamic anything = 42;
Dynamic type
List<int> numbers = [1, 2, 3];
List
Map<String, int> ages = {'Alice': 25};
Map
Set<int> unique = {1, 2, 3};
Set

Functions & Closures 6

int add(int a, int b) => a + b;
Arrow function
void greet(String name, [String? title]) { }
Optional positional parameter
void greet({required String name, int age = 0}) { }
Named parameters
Function fn = (x) => x * 2;
Closure
void Function(int) callback;
Function type
typedef Comparator<T> = int Function(T a, T b);
Type alias

Classes & Mixins 7

class Person { String name; Person(this.name); }
Class and constructor
class Student extends Person { }
Inheritance
class Flyable mixin Fly { }
mixin
class Bird extends Animal with Flyable { }
Use a mixin
abstract class Shape { double area(); }
Abstract class
class Singleton { static final instance = Singleton._(); Singleton._(); }
Singleton pattern
class Immutable { final int value; const Immutable(this.value); }
Immutable class

Null Safety 6

String? nullable;
Nullable declaration
nullable?.length
Safe call
nullable ?? 'default'
Null-coalescing operator
nullable!
Non-null assertion
if (nullable != null) { nullable.length; }
Type promotion
late String lateVar;
Late initialization (must be assigned before use)

Asynchronous 6

Future<int> fetchData() async { return 42; }
Async function
int result = await fetchData();
Await an async result
Stream<int> countStream() async* { yield 1; }
Async generator
await for (var value in stream) { }
Listen to a stream
Future.wait([future1, future2]);
Await multiple futures
Completer<int> completer = Completer();
Manually control a Future

Collection Operations 8

list.where((x) => x > 5).toList()
Filter
list.map((x) => x * 2).toList()
Map
list.reduce((a, b) => a + b)
Reduce
list.fold(0, (sum, x) => sum + x)
Fold
list.any((x) => x > 0)
Any exists
list.every((x) => x > 0)
All satisfy
list.sort((a, b) => a.compareTo(b))
Sort
list.groupBy((x) => x.category)
Group (needs the collection package)

Tips

  • Dart's null safety is a compile-time check; use ? and ?? to avoid runtime exceptions.
  • async/await is core to asynchronous programming; avoid blocking the UI thread.
  • mixin is Dart's way to achieve multiple inheritance; good for code reuse.

Official References

Each command links to its official documentation below, so you can verify the latest usage and read deeper.

Maintained by LaoHand

Publicly updated on Jul 21, 2026, continuously proofread against official docs.

Contact Us

Wrong command or description? Send us corrections, business inquiries or product feedback by email.

Contact Us