maplibre / flutter-maplibre-gl

Customizable, performant and vendor-free vector and raster maps, flutter wrapper for maplibre-native and maplibre-gl-js (fork of flutter-mapbox-gl/maps)
https://pub.dev/packages/maplibre_gl
Other
221 stars 120 forks source link

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

Open srinivas1100 opened 2 months ago

srinivas1100 commented 2 months ago

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);
              },
            )
Letalus commented 2 months ago

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 :/