Creating and Awaiting Futures
Produce and consume Future values.
Creating and Awaiting Futures is a free Dart Academy lesson on CoddyKit — lesson 2 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Dart Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
A Promise of a Value
A Future represents a value that is not ready yet but will arrive later, like a receipt you redeem when your order is done.
Future of a Type
A future is always typed by what it will deliver. A Future<int> promises an int once the async work completes.
Future<int> fetchScore() async {
return 42;
}Marking a Function async
Add the async keyword and the function automatically returns a Future. Its return value becomes the future completes value.
Future<String> greet() async {
return "hi";
}Awaiting a Result
Inside an async function, await pauses until the future completes, then hands you the plain unwrapped value.
final score = await fetchScore();
print(score); // 42await Does Not Block
While one function awaits, the event loop keeps running other work. await suspends just this function, not your whole program.
Simulating Delay
Use Future.delayed to wait a set duration before producing a value, perfect for mimicking a slow network call.
await Future.delayed(Duration(seconds: 1));
print("one second later");An Instant Future
Future.value wraps a ready value in a future, useful when an API expects a Future but you already have the answer.
Future<int> ready = Future.value(7);Chaining With then
Before async/await, you used then to run a callback once the future resolved. It is still handy for short chains.
fetchScore().then((s) => print(s));await Reads Cleaner
Compared to nested then callbacks, await lets async code read top to bottom like ordinary synchronous steps.
Returning From async
Whatever you return from an async function becomes the futures value. Return nothing and you get a Future<void>.
Awaiting Only in async
You can only use await inside a function marked async. Outside one, work with the Future via then instead.
Quick Check
Quick check on await behavior.
Recap: Futures
You now create futures with async, deliver values by returning, and unwrap them with await. Async code reads as cleanly as sync. 🚀
Frequently asked questions
Is the “Creating and Awaiting Futures” lesson free?
Yes — the full text of “Creating and Awaiting Futures” is free to read here on the web, and the Dart Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Dart Academy course, upgrade to CoddyKit PRO.
What will I learn in “Creating and Awaiting Futures”?
Produce and consume Future values. You practise Dart Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Dart Academy?
No prior experience is required. Dart Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 2 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Creating and Awaiting Futures” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Dart Academy lesson?
Yes. Every Dart Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- The Event Loop and Microtasks
- Creating and Awaiting Futures
- Error Handling in async Code
- Future.wait and Parallel Work