Skip to content

Commit

Permalink
fixed issue with map disposal on web (#895)
Browse files Browse the repository at this point in the history
  • Loading branch information
felix-ht authored Feb 4, 2022
1 parent 2824a75 commit 1b61a9c
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
5 changes: 5 additions & 0 deletions mapbox_gl_platform_interface/lib/src/callbacks.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ class ArgumentCallbacks<T> {
_callbacks.remove(callback);
}

/// Removes all callbacks
void clear() {
_callbacks.clear();
}

/// Whether this collection is empty.
bool get isEmpty => _callbacks.isEmpty;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,5 +136,23 @@ abstract class MapboxGlPlatform {

Future<void> addSource(String sourceId, SourceProperties properties);

void dispose() {}
@mustCallSuper
void dispose() {
// clear all callbacks to avoid cyclic refs
onInfoWindowTappedPlatform.clear();
onFeatureTappedPlatform.clear();
onFeatureDraggedPlatform.clear();
onCameraMoveStartedPlatform.clear();
onCameraMovePlatform.clear();
onCameraIdlePlatform.clear();
onMapStyleLoadedPlatform.clear();

onMapClickPlatform.clear();
onMapLongClickPlatform.clear();
onAttributionClickPlatform.clear();
onCameraTrackingChangedPlatform.clear();
onCameraTrackingDismissedPlatform.clear();
onMapIdlePlatform.clear();
onUserLocationUpdatedPlatform.clear();
}
}
6 changes: 6 additions & 0 deletions mapbox_gl_web/lib/src/mapbox_web_gl_platform.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ class MapboxWebGlPlatform extends MapboxGlPlatform
viewType: 'plugins.flutter.io/mapbox_gl_${this.hashCode}');
}

@override
void dispose() {
super.dispose();
_map.remove();
}

void _registerViewFactory(Function(int) callback, int identifier) {
// ignore: undefined_prefixed_name
ui.platformViewRegistry.registerViewFactory(
Expand Down

0 comments on commit 1b61a9c

Please sign in to comment.