-
-
Notifications
You must be signed in to change notification settings - Fork 84
Open
Description
Is there an existing issue for this?
- I have searched the existing issues
What happened?
ScaffoldMessenger.of(context) and Navigator are called after await expressions in multiple screens without checking mounted first. If the user navigates away before the async operation completes, the widget is unmounted and accessing context will throw:
"Looking up a deactivated widget's ancestor is unsafe"
This causes a runtime crash in production.
Affected Locations (7 places across 3 files)
| File | Line | Issue |
|---|---|---|
lib/screens/tasks/task_screen.dart |
108 | ScaffoldMessenger.of(context) in catch block after await |
lib/screens/tasks/task_screen.dart |
128 | ScaffoldMessenger.of(context) in catch block after await |
lib/screens/tasks/task_screen.dart |
174 | ScaffoldMessenger.of(context) after await Navigator.push |
lib/screens/tickets/ticket_screen.dart |
165 | ScaffoldMessenger.of(context) after await Navigator.push |
lib/screens/workspace/workspace_screen.dart |
83 | ScaffoldMessenger.of(context) after await in .then() |
lib/screens/workspace/workspace_screen.dart |
109 | ScaffoldMessenger.of(context) after await in .then() |
lib/screens/workspace/workspace_screen.dart |
135 | ScaffoldMessenger.of(context) after await in .then() |
Steps to Reproduce
- Open Task screen, quickly navigate away while a status update is in progress
- App crashes with
"Looking up a deactivated widget's ancestor is unsafe"
Expected Behavior
App checks if (mounted) before using context after any await.
Fix
Wrap every context usage after an await in a mounted check:
// BEFORE (unsafe)
} catch (e) {
ScaffoldMessenger.of(context).showSnackBar(...);
}
// AFTER (safe)
} catch (e) {
if (mounted) {
ScaffoldMessenger.of(context).showSnackBar(...);
}
}Evidence
flutter analyze reports:
info - Don't use 'BuildContext's across async gaps — task_screen.dart:108
info - Don't use 'BuildContext's across async gaps — task_screen.dart:128
info - Don't use 'BuildContext's across async gaps — task_screen.dart:174
info - Don't use 'BuildContext's across async gaps — ticket_screen.dart:165
info - Don't use 'BuildContext's across async gaps — workspace_screen.dart:83
info - Don't use 'BuildContext's across async gaps — workspace_screen.dart:109
info - Don't use 'BuildContext's across async gaps — workspace_screen.dart:135
Record
- I agree to follow this project's Code of Conduct
- I want to work on this issue
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels