AOSSIE-Org / AOSSIE-Org/Ell-ena

BUG: BuildContext used across async gaps causes crash in task, ticket and workspace screens

Aperta
#223 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
Dart
Stelle
54
Fork
110
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

### 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

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.