Closed
Description
Describe the issue
With discarded_futures
lint enabled the false positive is triggered when method returning a Future
is called from a non-async method and returned future is passed to another method or Flutter widget. In Flutter MultiFrameImageStreamCompleter
and FutureBuilder
both are taking Future
as a parameter.
Similarly, a future could be assigned to a variable and used later in a method, yet still discarded_futures
lint is raised.
To Reproduce
Here is a code snippet that is triggering issue. Note that FutureBuilder
is usually within Flutter's build()
method, which can't be async.
FutureBuilder<Widget?>(
future: _buildImage(context, ...), // ignore: discarded_futures
builder: (_, snapshot) => snapshot.hasData ? snapshot.data! : const Box(),
)
Where the _buildImage
method is declared like this:
Future<Widget?> _buildImage(context, ...) async {
...get image data asynchronously
return Image(...);
}
**Expected behavior**
This lint should not be raised when future is assigned to a a used local variable or passed down as a method or constructor parameter.
**Additional context**
N/A
Metadata
Metadata
Assignees
Labels
A lower priority bug or feature requestFor issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages.Issues with the analyzer's support for the linter packageIssues related to lint rules that report a problem when it isn't a problem.Incorrect behavior (everything from a crash to more subtle misbehavior)