dart async
Working with futures: async and await
The async and await keywords provide a declarative way to define asynchronous functions and use their results. Remember these two basic guidelines when using async and await:
To define an async function, add async before the function body:
The await keyword works only in async functions.
Here’s an example that converts main() from a synchronous to asynchronous function.
First, add the async keyword before the function body:
void main() async { ··· }
If the function has a declared return type, then update the type to be Future<T>, where T is the type of the value that the function returns. If the function doesn’t explicitly return a value, then the return type is Future<void>:
Future<void> main() async { ··· }
Now that you have an async function, you can use the await keyword to wait for a future to complete:
print(await createOrderMessage());