@@ -137,6 +137,11 @@ class GoogleMapController {
137
137
TileOverlaysController ? _tileOverlaysController;
138
138
GroundOverlaysController ? _groundOverlaysController;
139
139
140
+ StreamSubscription <void >? _onClickSubscription;
141
+ StreamSubscription <void >? _onRightClickSubscription;
142
+ StreamSubscription <void >? _onBoundsChangedSubscription;
143
+ StreamSubscription <void >? _onIdleSubscription;
144
+
140
145
// Keeps track if _attachGeometryControllers has been called or not.
141
146
bool _controllersBoundToMap = false ;
142
147
@@ -247,23 +252,25 @@ class GoogleMapController {
247
252
_streamController.add (WebMapReadyEvent (_mapId));
248
253
}
249
254
});
250
- map.onClick.listen ((gmaps.MapMouseEventOrIconMouseEvent event) {
255
+ _onClickSubscription =
256
+ map.onClick.listen ((gmaps.MapMouseEventOrIconMouseEvent event) {
251
257
assert (event.latLng != null );
252
258
if (! _streamController.isClosed) {
253
259
_streamController.add (
254
260
MapTapEvent (_mapId, gmLatLngToLatLng (event.latLng! )),
255
261
);
256
262
}
257
263
});
258
- map.onRightclick.listen ((gmaps.MapMouseEvent event) {
264
+ _onRightClickSubscription =
265
+ map.onRightclick.listen ((gmaps.MapMouseEvent event) {
259
266
assert (event.latLng != null );
260
267
if (! _streamController.isClosed) {
261
268
_streamController.add (
262
269
MapLongPressEvent (_mapId, gmLatLngToLatLng (event.latLng! )),
263
270
);
264
271
}
265
272
});
266
- map.onBoundsChanged.listen ((void _) {
273
+ _onBoundsChangedSubscription = map.onBoundsChanged.listen ((void _) {
267
274
if (! _mapIsMoving) {
268
275
_mapIsMoving = true ;
269
276
if (! _streamController.isClosed) {
@@ -276,7 +283,7 @@ class GoogleMapController {
276
283
);
277
284
}
278
285
});
279
- map.onIdle.listen ((void _) {
286
+ _onIdleSubscription = map.onIdle.listen ((void _) {
280
287
_mapIsMoving = false ;
281
288
if (! _streamController.isClosed) {
282
289
_streamController.add (CameraIdleEvent (_mapId));
@@ -600,6 +607,14 @@ class GoogleMapController {
600
607
_clusterManagersController = null ;
601
608
_tileOverlaysController = null ;
602
609
_groundOverlaysController = null ;
610
+ _onClickSubscription? .cancel ();
611
+ _onClickSubscription = null ;
612
+ _onRightClickSubscription? .cancel ();
613
+ _onRightClickSubscription = null ;
614
+ _onBoundsChangedSubscription? .cancel ();
615
+ _onBoundsChangedSubscription = null ;
616
+ _onIdleSubscription? .cancel ();
617
+ _onIdleSubscription = null ;
603
618
_streamController.close ();
604
619
}
605
620
}
0 commit comments