Dart, like other languages, works with synchronous and asynchronous functions.
I’ll explain in a grosser way, but then you research more on:
Synchronous Function
bool tarefaFinalizada() => tarefas[0].finalizada == true;
It is a function that when the execution of your system reaches it, it will wait for everything within it to be executed, to continue doing what it needs.
Asynchronous Function
Future<bool> getTarefas() async => await http.get('tarefas');
It is a function that the system performs, but does not wait for its termination, it performs this function and continues to do what it needs.
That is, the synchronous function, you expect the response of your function to perform certain action.
Future
This function will return a data from the future ~~Beware of Skynet
When you use asynchronous functions, you use the Future
to indicate that that function is asynchronous, or rather that it will return a value in the "future", for example, will return the values in 5 seconds.
await (Translating to BR -> "Wait")
Wait here until the function ends and get the result of it.
You use the await
when you make a call to return a future
. This causes the system to wait for the asynchronous function call to finish so that it runs the rest of the things. That is, it transforms an asynchronous function into synchronous.
Whenever you use a function that returns a Future
you will have to, at some point, add the await
to receive the correct value, otherwise you will always receive a Future<SeuTipo>
.
async
This function is asynchronous and at some point I may need to wait to pick up some data.
You need to use the async
in the functions where you will use the await
to indicate that the method will deal with asynchronous functions synchronously.
You can read a little more here on these links:
My advice...
Study more about programming and especially study more about the
Dart language and the Flutter framework!
Flutter is a fast and practical framework, but for those who already know a little about programming. It is better to start already understanding and doing things correctly, than to go tinkering as you learn... So train, test, ALWAYS READ the Flutter documentation that is very well made and organized.
Damn, this site is only for professionals!? Take it easy, seems to already go negative and voting to close without even reading the question
– rubStackOverflow
@rubStackOverflow yesterday had a discussion about it that you commented on another question hahahaha Ta difficult, mainly the tag Flutter (It seems to be a problem tag), ta right that many questions from Flutter the galley neither gives to the luxury of understanding how to ask a question here, but I don’t think it’s valid to go downvote at all... Even more the one that adds knowledge to the site (As they say it should be).
– Matheus Ribeiro
@Matheusribeiro I saw,
downvote
is trivialized.– rubStackOverflow