Ad space (banner)
Lesson 15 / 20

Asynchronous work (Future, async, await)

This lesson covers the basics of asynchronous programming, for work that takes time.

Future is the type representing a value you will get later. Marking a function async lets you use await inside it to wait for asynchronous work to finish.

The sample code simulates a delay with Future.delayed inside Future<String> fetchData() async { ... }, then waits for the result with await before displaying it.

A common early stumble is forgetting to mark the calling function async as well. await can only be used inside an async function.

In professional work, most time-consuming operations — fetching data from a server, reading a file — are written with async and await. It is unavoidable in Flutter development.

๐Ÿ“– Reference code
โœ๏ธ Your code
Type your code, then press "Run"

๐Ÿงช This site can't compile or run Dart directly, so it checks on the spot whether what you typed matches the reference code (scoring happens entirely in your browser โ€” nothing is sent anywhere).

Ad space (banner)
Ad space (in-article)