Is there a difference whether using await with return in Dart?
Since you are returning Future, in this exact case, even if you don`t await it, the foo(3) will return Future instead and it is the exact thing your function wants to return. and if u await it there, then it will await in the function and then return the value.
you don`t even need await in this case if foo return Future. Then the caller of bar will instead await the bar.
ArtS
Updated on December 25, 2022Comments
-
ArtS 11 months
In my flutter project, say there's a
foo(int x) async
function. Andbar() async
that looks like:Future bar() async { return foo(3); }
The
bar()
function is just a simple capsule forfoo(int x)
with a certain parameter. Andbar()
is used as thefuture
in aFutureBuilder
.I'm not sure if I should use
await
with return. I can't find related documentations online. So what's the difference betweenreturn foo(3)
andreturn await foo(3)
? Thank you!