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
| Concept | Flutter impact |
|---|---|
| Sound null safety | UI 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 await | Keep UI code readable while platform/storage/network work runs asynchronously |
| Isolates | Move expensive CPU work off the UI isolate |
Packages and pubspec.yaml | Every dependency changes build, platform, and security surface area |
dart analyze | Static checks that catch many issues before Flutter builds |
dart format | Stable 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:ioor FFI might not work on web.