Thuta Learning
AdvancedProgrammingbeginner

Async, Await, Future

Relax. We'll talk through this in plain words — no textbook voice.

Asynchronous programming is how you handle tasks that take a while without freezing the app. You'll use it for things like API calls, file loading, database queries, and network requests, using Future, async, await.

dart
Future<String> fetchUserOrder() async {
  await Future.delayed(Duration(seconds: 2));
  return 'Large latte';
}

void main() async {
  print('Fetching user order...');

  final order = await fetchUserOrder();

  print('Order: $order');
  print('Order fetched.');
}

fetchUserOrder() returns a Future, meaning you won't get the String value right away — it'll arrive later. await waits until the Future completes and then gives you the result.

You should see
Fetching user order... (2 seconds later) Order: Large latte Order fetched.

Easy traps

  • Forget await and you'll just get the Future object back, not the actual data you were after.