Back to results for “Asynchronous Programming”
Flutter › Dart Asynchronous Programming (Future & async/await)

What is a Future in Dart, and how does it represent a value that will not actually be available until some point later in time?

Beginner

Answer

A Future represents a value or an error that will become available at some point in the future, rather than immediately, and it is Dart's core mechanism for representing the result of an asynchronous operation, such as fetching data from a network server or reading a file from disk, both of which naturally take some amount of time to actually complete, and instead of your code blocking and waiting idly for that entire duration, a Future lets your program continue doing other useful work while that time consuming operation happens in the background.
Future<String> fetchUserName() {
  return Future.delayed(Duration(seconds: 2), () => 'Alex');
}
Real-world example A weather app calls a function returning a Future representing the eventual result of fetching current weather data from a remote server, allowing the app's interface to remain fully responsive while that network request is still in progress.

Common follow-ups: What is the difference between a Future and a Stream?;What happens if you never actually wait for or handle the result of a returned Future?