Async and Practical
Future Chain
.then().then()
.then(fn) runs fn once the prior future completes and produces the next future in the chain. Stacking .then calls gives a step-by-step pipeline; only the final future needs to be awaited. Because the chain starts from Future.value(...), no timers or external events are involved.
Program
Play the program to chain doubleIt and label onto a completed future.
future_chain.dart
int doubleIt(int n) => n * 2;
String label(int n) => 'score=$n';
Future<void> main() async {
var chain = Future.value(5).then(doubleIt).then(label);
var result = await chain;
print(result);
}
Future.value
`Future.value(5)` is already complete, so the chain has a value to push through right away.
.then
`.then(fn)` schedules `fn` on the prior future and yields a new future carrying `fn`'s return value.
await once
Only the final chained future needs `await`; intermediate `.then` callbacks already pass the value along.