Flutter Idiomatic Flutter
ASecurity`setState` must not run after the widget has been disposed. Any `await` is an async gap: the user may navigate away while the operation is running. Check `context.mounted` immediately after the await and before every later use of the context or state. ```dart Future<void> _saveProfile() async { setState(() => _isSaving = true); try { await repository.save(_draft); if (!context.mounted) return; ScaffoldMessenger.of(context).showSnackBar( const SnackBar(content: Text('Profile saved')), ); } cat...
- 584 stars
- 0 votes
- 0 copies
- 3 views
- Added September 5, 2026
Security analysis
100/100Pro scans all 12 files and shows the line behind each finding
npx -y skills add HoangNguyen0403/agent-skills-standard --skill flutter-idiomatic-flutter --agent claude-codeAre you the author of Flutter Idiomatic Flutter?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/hoangnguyen0403-flutter-idiomatic-flutter-agent-skills-standard)`setState` must not run after the widget has been disposed. Any `await` is an async gap: the user may navigate away while the operation is running. Check `context.mounted` immediately after the await and before every later use of the context or state.
```dart
Future<void> _saveProfile() async {
setState(() => _isSaving = true);
try {
await repository.save(_draft);
if (!context.mounted) return;
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('Profile saved')),
);
} catch (error) {
if (!context.mounted) return;
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text('Save failed: $error')),
);
} finally {
if (context.mounted) {
setState(() => _isSaving = false);
}
}
}
```
Do not use `mounted` as a one-time check before the `await`; it must be checked after the gap. If this operation belongs to application state rather than local presentation state, move it into a BLoC or Riverpod notifier and let the widget render that state. That also avoids a widget owning a long-lived controller or operation.
Files in this skill
- eval-1.baseline.md
- eval-1.with-skill.md
- eval-2.baseline.md
- eval-2.with-skill.md
- eval-3.baseline.md
- eval-3.with-skill.md
- trigger-1.md
- trigger-2.md
- trigger-3.md
- trigger-4.md
- trigger-5.md
Attribution
Related skills
View all in development →Comments
Loading comments…
Newsletter
Get the weekly list of safe new skills, and the ones we pulled.