diff --git a/packages/google_maps_flutter/lib/src/marker.dart b/packages/google_maps_flutter/lib/src/marker.dart index cd39f689422d..4289f7874c1b 100644 --- a/packages/google_maps_flutter/lib/src/marker.dart +++ b/packages/google_maps_flutter/lib/src/marker.dart @@ -274,15 +274,40 @@ class Marker { } @override - bool operator ==(Object other) { - if (identical(this, other)) return true; - if (other.runtimeType != runtimeType) return false; - final Marker typedOther = other; - return markerId == typedOther.markerId; - } + bool operator ==(Object other) => + identical(this, other) || + other is Marker && + runtimeType == other.runtimeType && + markerId == other.markerId && + alpha == other.alpha && + anchor == other.anchor && + consumeTapEvents == other.consumeTapEvents && + draggable == other.draggable && + flat == other.flat && + icon == other.icon && + infoWindow == other.infoWindow && + position == other.position && + rotation == other.rotation && + visible == other.visible && + zIndex == other.zIndex && + onTap == other.onTap; @override - int get hashCode => markerId.hashCode; + int get hashCode => hashValues( + markerId, + alpha, + anchor, + anchor, + consumeTapEvents, + draggable, + flat, + icon, + infoWindow, + position, + rotation, + visible, + zIndex, + onTap); @override String toString() { diff --git a/packages/google_maps_flutter/lib/src/marker_updates.dart b/packages/google_maps_flutter/lib/src/marker_updates.dart index 6c73b5e6a12d..88e555787104 100644 --- a/packages/google_maps_flutter/lib/src/marker_updates.dart +++ b/packages/google_maps_flutter/lib/src/marker_updates.dart @@ -24,6 +24,10 @@ class _MarkerUpdates { final Set prevMarkerIds = previousMarkers.keys.toSet(); final Set currentMarkerIds = currentMarkers.keys.toSet(); + final Set previousMarkersSet = + Set.of(previousMarkers.values); + final Set currentMarkersSet = Set.of(currentMarkers.values); + Marker idToCurrentMarker(MarkerId id) { return currentMarkers[id]; } @@ -36,10 +40,9 @@ class _MarkerUpdates { .map(idToCurrentMarker) .toSet(); - final Set _markersToChange = currentMarkerIds - .intersection(prevMarkerIds) - .map(idToCurrentMarker) - .toSet(); + final Set _markersToChange = currentMarkersSet + .difference(previousMarkersSet) + ..removeAll(_markersToAdd); markersToAdd = _markersToAdd; markerIdsToRemove = _markerIdsToRemove;