AOSSIE-Org / AOSSIE-Org/Ell-ena
BUG: BuildContext used across async gaps causes crash in task, ticket and workspace screens
- Ngôn ngữ chính
- Dart
- Star
- 54
- Fork
- 110
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Mô tả
### Is there an existing issue for this?
- [x] 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
1. Open Task screen, quickly navigate away while a status update is in progress
2. 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:
```dart
// 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
- [x] I agree to follow this project's Code of Conduct
- [x] I want to work on this issue
Hướng dẫn đóng góp
Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này
Đánh giá
Issue này chưa được đánh giá.