Skip to content

use_build_context_synchronously provides incorrect warning in some case #59093

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

Closed
imrhk opened this issue Mar 27, 2023 · 5 comments
Closed

use_build_context_synchronously provides incorrect warning in some case #59093

imrhk opened this issue Mar 27, 2023 · 5 comments
Labels
devexp-linter Issues with the analyzer's support for the linter package legacy-area-analyzer Use area-devexp instead. linter-set-flutter P4

Comments

@imrhk
Copy link

imrhk commented Mar 27, 2023

context.mounted if used with any operator reports warning of use_build_context_synchronously but without any operator, it works as expected.

For example,

 _someMethod(BuildContext context) async {
    await Future.delayed(const Duration(seconds: 8));

    if (context.mounted) {
      Navigator.of(context);
    }
  }

does not report any warning but

_someMethod(BuildContext context) async {
    await Future.delayed(const Duration(seconds: 8));

    if (!context.mounted) return; // or  if (context.mounted == false) or if (context.mounted == true)

    Navigator.of(context);
  }

reports warning.

@bwilkerson
Copy link
Member

The rule does not currently do any kind of flow / data analysis, and it's probably outside the scope of the rule to add such an analysis.

We could consider special casing some common patterns, but I don't think we can / should special case every possible pattern. I don't know whether if (!context.mounted) return; is common enough to justify special casing it.

@bwilkerson bwilkerson added the P4 label Mar 27, 2023
@imrhk
Copy link
Author

imrhk commented Mar 28, 2023

From https://dart-lang.github.io/linter/lints/use_build_context_synchronously.html

It is "Good" to use if (!context.mounted) return;. Either the example should be removed or warning should not be shown for this particular case as it is contradictory.

@kj415j45
Copy link

duplicated with #59009 ?

@imrhk
Copy link
Author

imrhk commented Mar 29, 2023

Closing this as it is duplicate of #59009

@imrhk imrhk closed this as completed Mar 29, 2023
@imrhk
Copy link
Author

imrhk commented Mar 29, 2023

Closing this as it is duplicate of #59009

@imrhk imrhk closed this as not planned Won't fix, can't repro, duplicate, stale Mar 29, 2023
@devoncarew devoncarew added devexp-linter Issues with the analyzer's support for the linter package legacy-area-analyzer Use area-devexp instead. labels Nov 19, 2024
@devoncarew devoncarew transferred this issue from dart-archive/linter Nov 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
devexp-linter Issues with the analyzer's support for the linter package legacy-area-analyzer Use area-devexp instead. linter-set-flutter P4
Projects
None yet
Development

No branches or pull requests

4 participants