Dart
02 / 02

Async, Mixins & the Flutter Toolchain

Async, Mixins & the Flutter Toolchain

Future vs. Stream

Future<String> fetchName() async {
  final response = await http.get(url);
  return response.body;
}

Stream<int> countdown() async* {
  for (int i = 3; i > 0; i--) {
    yield i;
    await Future.delayed(Duration(seconds: 1));
  }
}

Future = a single eventual value (one HTTP request). Stream = a sequence of values over time (repeated events). FutureBuilder/StreamBuilder are the Flutter widgets that reactively rebuild UI from each.

Mixins & Extension Methods

mixin Flyable {
  void fly() => print('Flying!');
}
class Bird extends Animal with Flyable {}

extension StringCasing on String {
  String capitalize() => this[0].toUpperCase() + substring(1);
}
'hello'.capitalize();  // extends String without modifying its source

Mixins work around single-inheritance limits, composing behavior from multiple sources into one class. Extension methods add functionality to types you don't own (built-ins, third-party packages) as if natively defined.

Factory Constructors & late

class Logger {
  static final Logger _instance = Logger._internal();
  factory Logger() => _instance;    // always returns the same instance
  Logger._internal();
}

class Widget {
  late String description;  // initialized after construction, before use
}

JIT for Hot Reload, AOT for Release

During development, JIT compilation enables Flutter's hot reload — patching running code almost instantly without a full restart. Release builds use AOT compilation to native machine code for optimal startup/runtime performance, with tree shaking excluding unreachable code to keep the shipped binary lean.

Keep your own version of these notes — editable, searchable, and organised by your stack.

Start free