Async and Await in Dart
To understand the use of async and await keywords, first you need to understand what is Future in Dart. A Future is used to represent a potential answer or error that will be available at some time in the future.
Suppose you want to fetch data from an API. For this, you need to send an HTTP request and wait for the API to respond and then use the data provided by the API in your application. If not wait for the API to respond then there will be a null value which will result in an error.
So, basically, you need to make Dart understand that it needs to wait for a valid answer before executing further code. That is where async and await comes into play.




The above example shows that until the function after the await keyword is executed completely, the next function will not be executed.
An async function runs synchronously (executes line after line) until the first await keyword. This means that within an async function body, all synchronous code before the first await keyword executes immediately.
If this article helped you in any way, please react with a clap and help it reach a wider audience 😄