Skip to content

BuildContext used across async gaps in multiple screens #41

@CrowdTypical

Description

@CrowdTypical

Description

Several screens and dialogs capture context before an await and use it afterwards. While mounted checks are present in most cases, there are inconsistencies where some paths miss the check.

Affected Files

  • lib/widgets/settle_up_dialog.dart — context used after dialog operations
  • lib/screens/group_details_screen.dart_loadData() sets state without mounted guard
  • lib/screens/bill_detail_screen.dart_loadData() in initState may complete after dispose

Recommended Fix

Always capture ScaffoldMessenger.of(context) and Navigator.of(context) before the await, then use the captured reference after.

// Before (unsafe)
await someAsyncOp();
if (mounted) {
  ScaffoldMessenger.of(context).showSnackBar(...);
}

// After (safe)
final messenger = ScaffoldMessenger.of(context);
await someAsyncOp();
if (mounted) {
  messenger.showSnackBar(...);
}

Priority

High — can cause crashes on slow devices or flaky networks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions