Having an asynchronous function that doesn't return a value, what's the ideal return type Future<Null>
or Future<void>
?, or more specifically, what's the difference in using either? Both are legal, and in both cases the return value of the function is a Future
that resolves to null
. The following code prints null
two times:
import 'dart:async';
Future<void> someAsync() async {}
Future<Null> otherAsync() async {}
main() {
someAsync().then((v) => print(v));
otherAsync().then((v) => print(v));
}
void
to accept any return value goes against the dart 2 policy of strong typing, so I guess that in the future returning a value withFuture<void>
won't be allowed, alsoNull
doesn't make sense as a type so my guess is that it will disappear in the future. Nice answer, thanks. – Calliecalligraphy