This repository was archived by the owner on Jul 16, 2023. It is now read-only.
This repository was archived by the owner on Jul 16, 2023. It is now read-only.
[BUG] avoid-redundant-async does not handle case where return value may be null #1147
Closed
Description
- Dart code metrics version: 5.4.0
- Dart sdk version: 2.18.6
What did you do? Please include the source code example causing the issue.
RefreshIndicator(
onRefresh: () async {
if (shouldRefresh) return apiCall();
}
)
https://api.flutter.dev/flutter/material/RefreshIndicator-class.html
What did you expect to happen?
In this case, the onRefresh
function may return a Future
when shouldRefresh
is true. But, when shouldRefresh
is false, the function returns null
. So the async
keyword is needed, but we are getting a lint error for avoid-redundant-async
What actually happened?
'async' keyword is redundant, consider removing it.
dart[avoid-redundant-async](https://dartcodemetrics.dev/docs/rules/common/avoid-redundant-async)
If the async
keyword is removed, we get this analysis error:
The body might complete normally, causing 'null' to be returned, but the return type, 'Future<void>', is a potentially non-nullable type.
Try adding either a return or a throw statement at the end. body_might_complete_normally
Are you willing to submit a pull request to fix this bug?
Maybe :)