Dart For Flutter

Dart is not just Flutter syntax. It controls null safety, async, packages, analysis, formatting, tests, native compilation, and web compilation.

Concepts You Need Early

ConceptFlutter impact
Sound null safetyUI state and models must express missing data explicitly
Future<T>One async result, often network, file, or platform call
Stream<T>Multiple async values, often auth state, database updates, or sockets
async and awaitKeep UI code readable while platform/storage/network work runs asynchronously
IsolatesMove expensive CPU work off the UI isolate
Packages and pubspec.yamlEvery dependency changes build, platform, and security surface area
dart analyzeStatic checks that catch many issues before Flutter builds
dart formatStable formatting before review and generated diffs

Async Shape

Future<List<Expense>> loadExpenses() async {
  final rows = await database.query('expenses');
  return rows.map(Expense.fromRow).toList();
}

Use a Future for a one-time load. Use a Stream when the UI should react to repeated changes.

Stream<List<Expense>> watchExpenses() {
  return repository.watchAll();
}

UI Isolate Rule

The Flutter UI runs on an isolate. Do not parse huge JSON, encrypt large files, or crunch reports in a widget build() method. Move heavy work to a repository/service and use isolates or platform APIs when needed.

Tooling Baseline

Run these before blaming Flutter:

dart format lib test
flutter analyze
flutter test

Gotcha: Dart web and Dart native are different deployment paths. A package that works on mobile/desktop through dart:io or FFI might not work on web.