Skip to content

discarded_futures lint false positive #59504

Closed
@ekuleshov

Description

@ekuleshov

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

No one assigned

    Labels

    P3A lower priority bug or feature requestarea-devexpFor issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages.devexp-linterIssues 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.type-bugIncorrect behavior (everything from a crash to more subtle misbehavior)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions