A guide to asynchronous programming in Flutter (Dart)

Dart is a single thread language, which means it works in a single execution thread! This can be a huge issue when you perform time-consuming tasks. For instance, when you create an application (with Flutter ❤), you do not want it to freeze when you make a request to your server (unless you do not like your users). Therefore, Dart implements Future objects.

Gaspard Merten
4 min readAug 7, 2019
Photo by Sonja Langford on Unsplash

Future

Future objects are representation of the result of an asynchronous operation that will be completed later on.

You can access the result of a Future by using the await keyword. But keep in mind that you can only use the await keyword in an asynchronous function which you declare by using the async keyword! You can specify the type of the returned value and if you do not return a concrete value you should specify the type as being void.

The Future object has very useful constructors. The default one takes an asynchronous function as an argument. The future will then complete when the function returns a value.

--

--

Gaspard Merten

Co-Founder & CTO @ GiveActions 🛠️ | Writer on Medium 🪶 | Flutter & Django ❤️ | Polytechnic School of Brussels 🎓| Mountain Lover 🗻