fix: guard BuildContext usage across async gaps in task, ticket, and workspace screens#226
Conversation
…ce screens Wrap ScaffoldMessenger.of(context) calls with mounted checks and pre-capture messenger before await to satisfy use_build_context_synchronously lint rule in task_screen.dart, ticket_screen.dart, and workspace_screen.dart. Fixes AOSSIE-Org#223
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (3)
WalkthroughThis PR fixes a critical bug where Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Suggested labels
Poem
🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
📝 Coding Plan
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary
Fixes #223
Resolves
use_build_context_synchronouslylint warnings in three screens whereScaffoldMessenger.of(context)was called after anawaitwithout amountedguard.Problem
After an
await(e.g.,await Navigator.push(...)), the widget may have been disposed. CallingScaffoldMessenger.of(context)on a staleBuildContextcan cause a runtime crash:The analyzer correctly flagged these with
use_build_context_synchronously.Files Changed
lib/screens/tasks/task_screen.dartScaffoldMessenger.of(context)afterawait Navigator.pushin FABonPressedlib/screens/tickets/ticket_screen.dartonPressedlib/screens/workspace/workspace_screen.dart.then((result) async {})callbacks afterawaitcallsFix Applied
Two complementary techniques used per Flutter best practices:
Pre-capture the messenger before the
await:mountedguard in.then()callbacks (workspace screen):Before / After
Before (
flutter analyze):After (
flutter analyze lib/screens/tasks/task_screen.dart lib/screens/tickets/ticket_screen.dart lib/screens/workspace/workspace_screen.dart):Zero
use_build_context_synchronouslywarnings remaining in these files.Checklist
flutter analyzerun — no new warnings introduceduse_build_context_synchronouslywarnings in the three files resolvedmountedcheck)Summary by CodeRabbit