Future API #1

In this lesson, you will learn to use Future API to perform asynchronous operations in Dart.

We'll cover the following

Future API

Another way to execute asynchronous operations is to use the Future API.

In the Future API, the then() method is used to register a callback, which fires upon the completion of Future.

These are two variants of using the Future API.

  • Future<String>: Future returning String data type .
  • Future<void>: Future returning void.

Future<String>

The example below transforms our earlier example code showcasing await and async into a Future API implementation. Lookout for the use of then() in the main() function. In this example, Future is returning a String.

By calling the asynchronous function makeDataCall() from main(), it will return a Future<String> and assign it to theFuture variable.

Get hands-on with 1200+ tech skills courses.