I've just stumbled upon a github repo containing an example of flutter application for google_sign_in package.
I'm confused about a particular usage of unawaited used inside the example :
Future<void> _handleAuthorizeScopes() async {
final bool isAuthorized = await _googleSignIn.requestScopes(scopes);
setState(() {
_isAuthorized = isAuthorized;
});
if (isAuthorized) {
unawaited(_handleGetContact(_currentUser!)); // --> this code
}
}
What confusing me is what's the difference between that and not using the unawaited function, i.e:
Future<void> _handleAuthorizeScopes() async {
final bool isAuthorized = await _googleSignIn.requestScopes(scopes);
setState(() {
_isAuthorized = isAuthorized;
});
if (isAuthorized) {
_handleGetContact(_currentUser!); // --> this code is changed
}
}
What I expect was that the result between the two approaches (using and not using unawaited) is the same, however if that's the case, then I'm even more confused of the need of the unawaited function.
Helps with linter messages, from the docs:
Explicitly ignores a future.
Not all futures need to be awaited. The Dart linter has an optional "unawaited futures" lint which enforces that potential futures (expressions with a static type of Future or Future?) in asynchronous functions are handled somehow. If a particular future value doesn't need to be awaited, you can call unawaited(...) with it, which will avoid the lint, simply because the expression no longer has type Future. Using unawaited has no other effect. You should use unawaited to convey the intention of deliberately not waiting for the future.