mapbox-maps-flutter
mapbox-maps-flutter copied to clipboard
Exception thrown after calling `dispose()` on MapboxMap
Environment
- Flutter version:
3.16.9
- mapbox_maps_flutter version:
0.5.1
- Device:
iPhone Simulator
- OS:
iOS 17.2
Steps to Reproduce
- Navigate to a screen with MapWidget
- Pop the screen with MapWidget Code: GitHub Gist
Description
I'm encountering an issue where an exception is thrown after exiting a screen and calling dispose()
on MapboxMap
. The exception message suggests that the MapboxMap
object is being used after being disposed.
Expected Behavior
After calling dispose()
on a MapboxMap
object, the object is disposed of properly and no exception is thrown.
Actual Behavior
The following exception is thrown:
[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: A MapboxMap was used after being disposed.
Once you have called dispose() on a MapboxMap, it can no longer be used.
#0 ChangeNotifier.debugAssertNotDisposed.<anonymous closure> (package:flutter/src/foundation/change_notifier.dart:179:9)
#1 ChangeNotifier.debugAssertNotDisposed (package:flutter/src/foundation/change_notifier.dart:186:6)
#2 ChangeNotifier.dispose (package:flutter/src/foundation/change_notifier.dart:375:27)
#3 MapboxMap.dispose (package:mapbox_maps_flutter/src/mapbox_map.dart:194:11)
#4 _MapWidgetState.dispose (package:mapbox_maps_flutter/src/map_widget.dart:208:18)
<asynchronous suspension>
The issue persists in 1.0.0 release
Have the same issue, anyone any luck in dealing with it?
Same problem here
I solved it in my case by NOT calling Map.dispose();
myself.
Doesn't that break when opening the same screen the second time?
Doesn't that break when opening the same screen the second time?
Not for me, seems it is already called by the MapBox widget itself, so I have no issues with that. Seems the issue came from disposing it a second time.
When opening the same screen for the second time, there is another problem with symbols.
`
I/flutter ( 5458): MissingPluginException(No implementation found for method source#setFeature on channel plugins.flutter.io/mapbox_maps_0)
E/flutter ( 5458): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: MissingPluginException(No implementation found for method source#setGeoJson on channel plugins.flutter.io/mapbox_maps_0)
E/flutter ( 5458): #0 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:332:7)
E/flutter ( 5458):
` I think the problem is around the mapbox_maps id
Doesn't that break when opening the same screen the second time?
I do this;
late MapboxMap? _mapController;
@override
void dispose() {
locationSubscription?.cancel();
//_mapController.dispose();
_mapController = null;
super.dispose();
}
//and access with ?
void getVisibleBounds(){
var visibleBounds = await _mapController?.coordinateBoundsForCamera(cameraState.toCameraOptions());
}