-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Closed
Labels
P3A lower priority bug or feature requestA lower priority bug or feature requestarea-devexpFor issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages.For issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages.devexp-linterIssues with the analyzer's support for the linter packageIssues with the analyzer's support for the linter packagelinter-false-positiveIssues related to lint rules that report a problem when it isn't a problem.Issues related to lint rules that report a problem when it isn't a problem.type-bugIncorrect behavior (everything from a crash to more subtle misbehavior)Incorrect behavior (everything from a crash to more subtle misbehavior)
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
FMorschel and bsutton
Metadata
Metadata
Assignees
Labels
P3A lower priority bug or feature requestA lower priority bug or feature requestarea-devexpFor issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages.For issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages.devexp-linterIssues with the analyzer's support for the linter packageIssues with the analyzer's support for the linter packagelinter-false-positiveIssues related to lint rules that report a problem when it isn't a problem.Issues related to lint rules that report a problem when it isn't a problem.type-bugIncorrect behavior (everything from a crash to more subtle misbehavior)Incorrect behavior (everything from a crash to more subtle misbehavior)