Dart uses Future
objects whenever there might be a delay in the execution of the code,
say reading the contents of a File or launching a Process. Running chaining Futures such that they run one after the other requires returning a future from within the Future:
Future<X> f1 = action1();
f1 = f1.then((x) => action2());
The key here is the re-assignment of f1
to the result of the then
call.
To chain an arbitrarily long list of Futures, you can setup the code like this: