Asynchronous Code in Dart: The dart:async Library

At some point during your Dart development process, you might need to call a method without affecting the execution of your code, or call a library method that has been declared as an async method.

That’s when you realize the necessity for asynchronous code and the dart:async built-in Dart library, which allows async functions to return either a Future or a Stream.

The Future

The Future is the most basic object type related to asynchronous methods—it is the return type of all async functions, including void ones:

 Future<​void​> doSomethingThatTakesLong() async {
 // do something
 }
 void​ ​callingSyncFunction​() {
  doSomethingThatTakesLong();
 /* the code won't wait for the function to ...

Get Programming Flutter now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.