-
Notifications
You must be signed in to change notification settings - Fork 170
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
BuildContext across async gaps with mounted check false positive #5069
Comments
Is |
This is a function |
I see. Can you provide a full reproduction? I cannot reproduce this issue in unit tests. |
@goderbauer could you clarify for me, in this code: class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) => const Scaffold(
body: Text(
'You have pushed the button this many times:',
),
);
Future<int?> test() async {
await Future.delayed(const Duration(seconds: 1));
return 1;
}
Future<void> newPhoto() async {
await showDialog(
context: context,
builder: (BuildContext context) => AlertDialog(
actions: [
TextButton(
onPressed: () async {
int? result = await test();
if (!mounted) return;
Navigator.of(context).pop(result);
},
),
],
));
}
} (simplified from https://github.com/vendelin8/dart-lintbug/blob/main/lib/main.dart) Key points:
Do we need to guard that use of the local |
You are using the local context in |
OK good, the docs are accurate on this question. Thanks!
|
Ok, thanks! |
Describe the issue
Lint error
use_build_context_synchronously
when it was already checkedTo Reproduce
Expected behavior
No lint infos, because
mounted
was already checked previously.Additional context
The text was updated successfully, but these errors were encountered: