fix: Guard BuildContext usage across async gaps (use_build_context_synchronously)#202
fix: Guard BuildContext usage across async gaps (use_build_context_synchronously)#202Muneerali199 wants to merge 1 commit intoAOSSIE-Org:mainfrom
Conversation
Resolves use_build_context_synchronously warnings in patient and therapist apps: - patient/book_appointment.dart: move mounted check before context use; refactor _selectTimeSlot to use State.context directly - patient/therapist_provider.dart: add context.mounted guard before ScaffoldMessenger calls after await - therapist/personal_details_screen.dart: pre-capture Navigator and ScaffoldMessenger before await; use single if (!mounted) return guard Closes AOSSIE-Org#197
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughFixes four instances of Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 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 #197
Resolves 4
use_build_context_synchronouslywarnings across both apps. UsingBuildContextafter anawaitwithout a propermountedguard can cause a runtime crash if the widget has been unmounted during the async operation.Changes
patient/lib/presentation/result/book_appointment.dartif (!mounted) returnbefore the post-await context usage_selectTimeSlotto useState.contextdirectly instead of accepting aBuildContextparameter, eliminating the stale-context risk entirelypatient/lib/provider/therapist_provider.dartif (!context.mounted) returnguard before eachScaffoldMessenger.of(context)call that followsawait supabase.from(...).insert(...)therapist/lib/presentation/auth/personal_details_screen.dartNavigator.of(context)andScaffoldMessenger.of(context)into local variables before theawaitcallif (mounted)checks with a singleif (!mounted) returnimmediately after theawaitBefore
After
Checklist
flutter analyzerun after all changes — no new warnings introducedif (!mounted) returnplaced immediately after eachawaitbefore any context accessmountedcheck alone is insufficient (build callback context)Summary by CodeRabbit
Bug Fixes
Refactor