Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Flutter Android: App Crashes When Switching Screens After Enabling myLocationEnabled on Map Load #483

Open
srinivas1100 opened this issue Jul 31, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@srinivas1100
Copy link

Platforms

android

Version of flutter maplibre_gl

0.20.0

Bug Description

Bug:

When enabling myLocationEnabled to true once the map is fully loaded, the Android application crashes when navigating to another screen. This results in a significant crash report rate of 50% in my live application.

Impact:

This issue affects 50% of my live application's users, leading to a high crash rate and poor user experience.

Steps to Reproduce

  1. Open the application.
  2. Ensure there is a bottom navigation bar with three tabs:
    First tab: Map view
    Second tab: Normal view
    Third tab: Normal view
  3. Load the map in the first tab and set myLocationEnabled to true.
  4. Switch to the second or third tab.
  5. Switch back to the first tab (Map view).
  6. Observe the application crashing with the error: “Attempting to update a widget after it has been disposed.”

Expected Results

The application should allow users to switch screens without crashing after enabling myLocationEnabled on the map.

Actual Results

The application crashes upon navigating to switching another screen, causing a significant number of crashes in the live application.

Code Sample

MapLibreMap(
              styleString:
                  'https://api.radar.io/maps/styles/${Get.isDarkMode ? "radar-dark-v1" : "radar-default-v1"}?publishableKey=$publishableKey',
              initialCameraPosition: con.initialCamerPosition,
              tiltGesturesEnabled: false,
              rotateGesturesEnabled: false,
              myLocationEnabled: locationEnabled,
              // onUserLocationUpdated: (location) {},
              onMapCreated: (c) => onMapCreated(c),
              onStyleLoadedCallback: () => onStyleLoaded(context),
              onMapClick: (point, latLng) async {
                con.anotherLocation = null;
                con.selectedPlayIndex = -1;
                con.homePanelController.panelPosition = 0;
                mapController?.clearSymbols();
                userCurrentLocaiton.userLocationPosition = Position(
                    longitude: latLng.longitude,
                    latitude: latLng.latitude,
                    timestamp: DateTime.now(),
                    accuracy: 0,
                    altitude: 0,
                    altitudeAccuracy: 0,
                    heading: 0,
                    headingAccuracy: 0,
                    speed: 0,
                    speedAccuracy: 0);

                await con.anotherLocationLandmarks(latLng: latLng);
              },
            )
@srinivas1100 srinivas1100 added the bug Something isn't working label Jul 31, 2024
@Letalus
Copy link

Letalus commented Aug 6, 2024

workaround for now was following for us:
The myLocationEnabled property must only be set once onStyleLoadedCallback is triggered.
Changing this property before this callback is triggered will result in this bug, which also right now is a major problem for all our android users :/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants