Thuta Learning
AdvancedMobile Developmentbeginner

Async: Futures

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

Not all data in an app is available instantly. API calls, file reads, database queries, and location requests all take time. In Dart, a Future represents a value that will arrive later. async/await is syntax that makes time-consuming code easier to read.

dart
Future<String> fetchUserName() async {
  await Future.delayed(const Duration(seconds: 2));
  return 'Sai';
}

void main() async {
  print('Loading user...');
  final name = await fetchUserName();
  print('Hello, $name');
}
You should see
The console shows "Loading user...", then after 2 seconds, "Hello, Sai" appears.

Next Steps

Once you've got the async basics down, learn how to fetch API data using the http package.

Easy traps

  • If you print a Future directly without await, you'll get something like "Instance of 'Future'". Use await if you want the actual result.
Async: Futures | Thuta Learning