FLUTTER INTERVIEW QUESTIONS

How to wait for the Future(s) in Dart/Flutter?

Jelena Lecic
Flutter Africa
Published in
3 min readAug 19, 2020

--

Futures are one of the most used Dart language features and it’s really important to know all the ways we can wait for fetching their results.

This is a simple async function, with a Future in it, that will finish after 3 seconds(imagine some API call or something like that):

As you can see, function was started, delayed Future initiated but program continued with execution and reached the end of simpleAsyncFunction(). After 3 seconds, delayed Future was executed and its result was printed out from .then() callback.

If you do not want to reach the end of the simpleAsyncFunction() before this delayed Future finishes, put an await in front of it and its execution will stop until Future finishes:

But, what happens if you need to have some async work done from within our delayed Future?

--

--