Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

False positives for FutureBuilders when passing future functions to the future parameter. #1

Open
RemcoSchrijver opened this issue May 13, 2023 · 4 comments

Comments

@RemcoSchrijver
Copy link

Really like the package, only problem I'm having right now is that FutureBuilders spawns false positives when assigning a function to be used as a future.

An example would be
Future<String> getValue() async {
  await Future.delayed(Duration(seconds: 3));
  return 'Woolha';
}

FutureBuilder<String>(
  future: getValue(),
  builder: (
    BuildContext context,
    AsyncSnapshot<String> snapshot,
    ) {
      print(snapshot.connectionState);
      if (snapshot.connectionState == ConnectionState.waiting) {
        return CircularProgressIndicator();
      } else if (snapshot.connectionState == ConnectionState.done) {
      if (snapshot.hasError) {
         return const Text('Error');
       } else if (snapshot.hasData) {
         return Text(snapshot.data);
       } else {
         return const Text('Empty data');
       }
     } else {
       return Text('State: ${snapshot.connectionState}');
     }
  },
)

And getValue() is now rightfully marked as non-awaited future, however because this is a future builder this function is not used as such. Is this a user error on my part or is this just a false positive part of the framework?

@MelbourneDeveloper
Copy link
Owner

@RemcoSchrijver, yes, I get this one all the time.

Can you give me the exact lint so I can be sure we're talking about the same thing? You can just hover over the error to see it.

You can easily turn the error off in your analysis_options.yaml, but it's a very good lint in most scenarios. Not awaiting the future is one of the most common programming mistakes to make and often results in bugs.

I usually just end up ignoring this. in these scenarios, but I believe it might be worth raising an issue in the GitHub repo for for the lint.

@RemcoSchrijver
Copy link
Author

@MelbourneDeveloper yes I also like this one because it forces me to document which async calls I purposefully unawait. The linting error I get is this one:

Don't invoke asynchronous functions in non-async blocks.

It might be good indeed to raise an issue on this, but for now how would I go along ignoring these or could I set these as warnings?

@MelbourneDeveloper
Copy link
Owner

@RemcoSchrijver

how would I go along ignoring these or could I set these as warnings?

I currently ignore these at the line level, but I feel like it's a long-term problem, and we need to log something with the analyzer team. I believe this is the folder inside the Dart git repo for the analyzer. I think it would be worth logging an issue here. Let me know about it because I will add my comments as well.

https://github.com/dart-lang/sdk/tree/main/pkg/analyzer

@RemcoSchrijver
Copy link
Author

Alright filed an issue upstream for the analyzer repo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants