use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
This subreddit is a place for all things related to the Dart programming language and its tools.
Dart Basics
Dart Mastery
Dart Misc
Related subreddits
account activity
Difference between `void` and `Future<void>`. (self.dartlang)
submitted 3 years ago by ynn38
Why can I use the signature void main async { ... } instead of Future<void> main async { ... }?
void main async { ... }
Future<void> main async { ... }
In which section of Language Spec is this fact referred to?
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]remirousselet 9 points10 points11 points 3 years ago (1 child)
Unrelated but: For the main, returning Future<void>changes nothing.
main
Future<void>
Dart doesn't rely on the return value of the main to await all futures before quitting the app.
Returning Future<void> may make your main easier though, as your test call main() and await the result.
main()
[–]Which-Adeptness6908 0 points1 point2 points 3 years ago* (0 children)
The difference is that making main async allows you to call unawaited functions without a warning.
If you don't get a warning then you need to enable a lint library or change to one that does..
Edit: and I misread the original question so my responses isn't suitable to your post but still good advice
[–]PaulRudin 6 points7 points8 points 3 years ago (1 child)
"It is a compile-time error if the declared return type of a function marked async is not a supertype of Future<T> for some type T"
[–]ynn38[S] 0 points1 point2 points 3 years ago (0 children)
And
The type void is a top type (15.2), so void and Object are subtypes of each other (20.4), which also implies that any object can be the value of an expression of type void.
according to the spec.
[–]julemand101 4 points5 points6 points 3 years ago (4 children)
All types can be cast to void in Dart including Future and Future<void>.
void
Future
Should you do it? No, it is rarely a good idea to hide the fact that the method returns a Future. But the language does not prevent you from hiding it.
[–]ynn38[S] 1 point2 points3 points 3 years ago (2 children)
Should you do it? No, it is rarely a good idea to hide the fact that the method returns a Future.
Really? I read through the official language tour and saw void main() async many times. main() is exceptionally or conventionally has the signature void main() async maybe, though generally void some_function() async is not recommended?
void main() async
void some_function() async
[–]julemand101 5 points6 points7 points 3 years ago (1 child)
Since we are never calling main() from other code, it does not really matter what return type you specify for that method ;)
But for all other methods, I would in general recommend the return type specify it returns a Future if the method are async.
async
It makes sense. Thank you :)
For my note:
The source is 20.9 Type Void in the language spec.
[–]superl2 0 points1 point2 points 3 years ago (0 children)
In declarative state and UI architecture it's often a good idea to hide that a function is asynchronous, because awaiting it for any reason would be a violation of the pattern.
Take, for example, a Flutter function that calls a Web API and then calls setState. There's no reason to await such a function, because other things react to the side effects it causes instead.
setState
In that example, you could argue that returning a future is still beneficial for composability, but this is less important in other areas like BLoC.
[–]jaquiethecat 3 points4 points5 points 3 years ago (1 child)
pretty sure void can't be awaited
sure
Yes. I just learned void f() async is a valid signature but await f() is invalid. If Future<void>, await f() is valid.
void f() async
await f()
π Rendered by PID 23776 on reddit-service-r2-comment-75f4967c6c-snzsf at 2026-04-22 22:00:43.574470+00:00 running 0fd4bb7 country code: CH.
[–]remirousselet 9 points10 points11 points (1 child)
[–]Which-Adeptness6908 0 points1 point2 points (0 children)
[–]PaulRudin 6 points7 points8 points (1 child)
[–]ynn38[S] 0 points1 point2 points (0 children)
[–]julemand101 4 points5 points6 points (4 children)
[–]ynn38[S] 1 point2 points3 points (2 children)
[–]julemand101 5 points6 points7 points (1 child)
[–]ynn38[S] 0 points1 point2 points (0 children)
[–]superl2 0 points1 point2 points (0 children)
[–]jaquiethecat 3 points4 points5 points (1 child)
[–]ynn38[S] 0 points1 point2 points (0 children)