mapbox / mapbox-maps-flutter

Interactive, thoroughly customizable maps for Flutter powered by Mapbox Maps SDK
https://www.mapbox.com/mobile-maps-sdk
Other
295 stars 121 forks source link

Fix issue Mapbox used after being disposed #751

Open mayananand369 opened 3 weeks ago

mayananand369 commented 3 weeks ago

I have a logout button in my app. After logging out, an exception is being thrown which says: A MapboxMap was used after being disposed. Once you have called dispose() on a MapboxMap, it can no longer be used.

Below are the relevant codes:

 void _showLogoutConfirmationDialogUsing(
    BuildContext context,
  ) =>
      ActionDialog.show(
        context,
        content: context.localize.areYouSureYouWantToLogout,
        onActionDismissed: () {
          Navigator.of(
            context,
          ).pop();
        },
        onActionConfirmed: () {
          Navigator.of(
            context,
          ).pop();

          context.read<Web3AuthLogoutBloc>().add(
                const Web3AuthLogoutEvent.logout(),
              );
        },
      );
 @override
  void dispose() {
    _mapboxMap?.dispose();
    _clickedRestriction.dispose();
    _centerLocationNotifier.dispose();
    _mapStyleNotifier.dispose();

    super.dispose();
  }

https://github.com/user-attachments/assets/b79c8405-ffd2-4216-a27f-681de923c213

evil159 commented 3 weeks ago

@mayananand369 could you put a breakpoint in MapboxMap.dispose(), is it called twice by any chance?