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

fixed issue with map disposal on web #895

Merged
merged 1 commit into from
Feb 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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