diff --git a/AUTHORS b/AUTHORS index a24dfd196966..ed6942ae1a6e 100644 --- a/AUTHORS +++ b/AUTHORS @@ -43,3 +43,4 @@ Audrius Karosevicius Lukasz Piliszczuk SoundReply Solutions GmbH Rafal Wachol +Pau Picas \ No newline at end of file diff --git a/packages/google_maps_flutter/CHANGELOG.md b/packages/google_maps_flutter/CHANGELOG.md index 2f5983e0cbcf..c88a00be904a 100644 --- a/packages/google_maps_flutter/CHANGELOG.md +++ b/packages/google_maps_flutter/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.5.21 + +* Don't recreate map elements if they didn't change since last widget build. + ## 0.5.20+6 * Adds support for toggling the traffic layer diff --git a/packages/google_maps_flutter/lib/src/circle.dart b/packages/google_maps_flutter/lib/src/circle.dart index d09d3c492a75..eefb8c021fa6 100644 --- a/packages/google_maps_flutter/lib/src/circle.dart +++ b/packages/google_maps_flutter/lib/src/circle.dart @@ -141,7 +141,16 @@ class Circle { if (identical(this, other)) return true; if (other.runtimeType != runtimeType) return false; final Circle typedOther = other; - return circleId == typedOther.circleId; + return circleId == typedOther.circleId && + consumeTapEvents == typedOther.consumeTapEvents && + fillColor == typedOther.fillColor && + center == typedOther.center && + radius == typedOther.radius && + strokeColor == typedOther.strokeColor && + strokeWidth == typedOther.strokeWidth && + visible == typedOther.visible && + zIndex == typedOther.zIndex && + onTap == typedOther.onTap; } @override diff --git a/packages/google_maps_flutter/lib/src/circle_updates.dart b/packages/google_maps_flutter/lib/src/circle_updates.dart index 5dddb3a8ad15..c977c4182c98 100644 --- a/packages/google_maps_flutter/lib/src/circle_updates.dart +++ b/packages/google_maps_flutter/lib/src/circle_updates.dart @@ -36,9 +36,17 @@ class _CircleUpdates { .map(idToCurrentCircle) .toSet(); + /// Returns `true` if [current] is not equals to previous one with the + /// same id. + bool hasChanged(Circle current) { + final Circle previous = previousCircles[current.circleId]; + return current != previous; + } + final Set _circlesToChange = currentCircleIds .intersection(prevCircleIds) .map(idToCurrentCircle) + .where(hasChanged) .toSet(); circlesToAdd = _circlesToAdd; diff --git a/packages/google_maps_flutter/lib/src/marker.dart b/packages/google_maps_flutter/lib/src/marker.dart index 1f64f0ee19ff..4a087f797cdf 100644 --- a/packages/google_maps_flutter/lib/src/marker.dart +++ b/packages/google_maps_flutter/lib/src/marker.dart @@ -283,7 +283,19 @@ class Marker { if (identical(this, other)) return true; if (other.runtimeType != runtimeType) return false; final Marker typedOther = other; - return markerId == typedOther.markerId; + return markerId == typedOther.markerId && + alpha == typedOther.alpha && + anchor == typedOther.anchor && + consumeTapEvents == typedOther.consumeTapEvents && + draggable == typedOther.draggable && + flat == typedOther.flat && + icon == typedOther.icon && + infoWindow == typedOther.infoWindow && + position == typedOther.position && + rotation == typedOther.rotation && + visible == typedOther.visible && + zIndex == typedOther.zIndex && + onTap == typedOther.onTap; } @override diff --git a/packages/google_maps_flutter/lib/src/marker_updates.dart b/packages/google_maps_flutter/lib/src/marker_updates.dart index 6c73b5e6a12d..d4a08255e069 100644 --- a/packages/google_maps_flutter/lib/src/marker_updates.dart +++ b/packages/google_maps_flutter/lib/src/marker_updates.dart @@ -36,9 +36,17 @@ class _MarkerUpdates { .map(idToCurrentMarker) .toSet(); + /// Returns `true` if [current] is not equals to previous one with the + /// same id. + bool hasChanged(Marker current) { + final Marker previous = previousMarkers[current.markerId]; + return current != previous; + } + final Set _markersToChange = currentMarkerIds .intersection(prevMarkerIds) .map(idToCurrentMarker) + .where(hasChanged) .toSet(); markersToAdd = _markersToAdd; diff --git a/packages/google_maps_flutter/lib/src/polygon.dart b/packages/google_maps_flutter/lib/src/polygon.dart index 7592cb78d393..2230ae81afaf 100644 --- a/packages/google_maps_flutter/lib/src/polygon.dart +++ b/packages/google_maps_flutter/lib/src/polygon.dart @@ -150,7 +150,16 @@ class Polygon { if (identical(this, other)) return true; if (other.runtimeType != runtimeType) return false; final Polygon typedOther = other; - return polygonId == typedOther.polygonId; + return polygonId == typedOther.polygonId && + consumeTapEvents == typedOther.consumeTapEvents && + fillColor == typedOther.fillColor && + geodesic == typedOther.geodesic && + listEquals(points, typedOther.points) && + visible == typedOther.visible && + strokeColor == typedOther.strokeColor && + strokeWidth == typedOther.strokeWidth && + zIndex == typedOther.zIndex && + onTap == typedOther.onTap; } @override diff --git a/packages/google_maps_flutter/lib/src/polygon_updates.dart b/packages/google_maps_flutter/lib/src/polygon_updates.dart index c7a04f426074..5a14c6b8ec5c 100644 --- a/packages/google_maps_flutter/lib/src/polygon_updates.dart +++ b/packages/google_maps_flutter/lib/src/polygon_updates.dart @@ -36,9 +36,17 @@ class _PolygonUpdates { .map(idToCurrentPolygon) .toSet(); + /// Returns `true` if [current] is not equals to previous one with the + /// same id. + bool hasChanged(Polygon current) { + final Polygon previous = previousPolygons[current.polygonId]; + return current != previous; + } + final Set _polygonsToChange = currentPolygonIds .intersection(prevPolygonIds) .map(idToCurrentPolygon) + .where(hasChanged) .toSet(); polygonsToAdd = _polygonsToAdd; diff --git a/packages/google_maps_flutter/lib/src/polyline.dart b/packages/google_maps_flutter/lib/src/polyline.dart index 5e93669a596e..7454711dd6b1 100644 --- a/packages/google_maps_flutter/lib/src/polyline.dart +++ b/packages/google_maps_flutter/lib/src/polyline.dart @@ -192,7 +192,19 @@ class Polyline { if (identical(this, other)) return true; if (other.runtimeType != runtimeType) return false; final Polyline typedOther = other; - return polylineId == typedOther.polylineId; + return polylineId == typedOther.polylineId && + consumeTapEvents == typedOther.consumeTapEvents && + color == typedOther.color && + geodesic == typedOther.geodesic && + jointType == typedOther.jointType && + listEquals(patterns, typedOther.patterns) && + listEquals(points, typedOther.points) && + startCap == typedOther.startCap && + endCap == typedOther.endCap && + visible == typedOther.visible && + width == typedOther.width && + zIndex == typedOther.zIndex && + onTap == typedOther.onTap; } @override diff --git a/packages/google_maps_flutter/lib/src/polyline_updates.dart b/packages/google_maps_flutter/lib/src/polyline_updates.dart index 5d82597fd212..ed972a51c8bf 100644 --- a/packages/google_maps_flutter/lib/src/polyline_updates.dart +++ b/packages/google_maps_flutter/lib/src/polyline_updates.dart @@ -38,9 +38,17 @@ class _PolylineUpdates { .map(idToCurrentPolyline) .toSet(); + /// Returns `true` if [current] is not equals to previous one with the + /// same id. + bool hasChanged(Polyline current) { + final Polyline previous = previousPolylines[current.polylineId]; + return current != previous; + } + final Set _polylinesToChange = currentPolylineIds .intersection(prevPolylineIds) .map(idToCurrentPolyline) + .where(hasChanged) .toSet(); polylinesToAdd = _polylinesToAdd; diff --git a/packages/google_maps_flutter/pubspec.yaml b/packages/google_maps_flutter/pubspec.yaml index 7504c1dd41a6..f8a852998d42 100644 --- a/packages/google_maps_flutter/pubspec.yaml +++ b/packages/google_maps_flutter/pubspec.yaml @@ -2,7 +2,7 @@ name: google_maps_flutter description: A Flutter plugin for integrating Google Maps in iOS and Android applications. author: Flutter Team homepage: https://github.com/flutter/plugins/tree/master/packages/google_maps_flutter -version: 0.5.20+6 +version: 0.5.21 dependencies: flutter: diff --git a/packages/google_maps_flutter/test/circle_updates_test.dart b/packages/google_maps_flutter/test/circle_updates_test.dart index 4a3f14134e34..001b4d58a0f1 100644 --- a/packages/google_maps_flutter/test/circle_updates_test.dart +++ b/packages/google_maps_flutter/test/circle_updates_test.dart @@ -75,10 +75,10 @@ void main() { final Circle addedCircle = platformGoogleMap.circlesToAdd.first; expect(addedCircle, equals(c2)); + expect(platformGoogleMap.circleIdsToRemove.isEmpty, true); - expect(platformGoogleMap.circlesToChange.length, 1); - expect(platformGoogleMap.circlesToChange.first, equals(c1)); + expect(platformGoogleMap.circlesToChange.isEmpty, true); }); testWidgets("Removing a circle", (WidgetTester tester) async { @@ -172,29 +172,22 @@ void main() { expect(platformGoogleMap.circleIdsToRemove.first, equals(c3.circleId)); }); - testWidgets( - "Partial Update", - (WidgetTester tester) async { - final Circle c1 = Circle(circleId: CircleId("circle_1")); - Circle c2 = Circle(circleId: CircleId("circle_2")); - final Set prev = _toSet(c1: c1, c2: c2); - c2 = Circle(circleId: CircleId("circle_2"), radius: 10); - final Set cur = _toSet(c1: c1, c2: c2); - - await tester.pumpWidget(_mapWithCircles(prev)); - await tester.pumpWidget(_mapWithCircles(cur)); - - final FakePlatformGoogleMap platformGoogleMap = - fakePlatformViewsController.lastCreatedView; - - expect(platformGoogleMap.circlesToChange, _toSet(c2: c2)); - expect(platformGoogleMap.circleIdsToRemove.isEmpty, true); - expect(platformGoogleMap.circlesToAdd.isEmpty, true); - }, - // The test is currently broken due to a bug (we're updating all circles - // instead of just the ones that were changed): - // https://github.com/flutter/flutter/issues/30764 - // TODO(amirh): enable this test when the issue is fixed. - skip: true, - ); + testWidgets("Partial Update", (WidgetTester tester) async { + final Circle c1 = Circle(circleId: CircleId("circle_1")); + final Circle c2 = Circle(circleId: CircleId("circle_2")); + Circle c3 = Circle(circleId: CircleId("circle_3")); + final Set prev = _toSet(c1: c1, c2: c2, c3: c3); + c3 = Circle(circleId: CircleId("circle_3"), radius: 10); + final Set cur = _toSet(c1: c1, c2: c2, c3: c3); + + await tester.pumpWidget(_mapWithCircles(prev)); + await tester.pumpWidget(_mapWithCircles(cur)); + + final FakePlatformGoogleMap platformGoogleMap = + fakePlatformViewsController.lastCreatedView; + + expect(platformGoogleMap.circlesToChange, _toSet(c3: c3)); + expect(platformGoogleMap.circleIdsToRemove.isEmpty, true); + expect(platformGoogleMap.circlesToAdd.isEmpty, true); + }); } diff --git a/packages/google_maps_flutter/test/fake_maps_controllers.dart b/packages/google_maps_flutter/test/fake_maps_controllers.dart index d892ea1a7794..0ae12c815ff3 100644 --- a/packages/google_maps_flutter/test/fake_maps_controllers.dart +++ b/packages/google_maps_flutter/test/fake_maps_controllers.dart @@ -133,6 +133,7 @@ class FakePlatformGoogleMap { final Set result = Set(); for (Map markerData in markersData) { final String markerId = markerData['markerId']; + final double alpha = markerData['alpha']; final bool draggable = markerData['draggable']; final bool visible = markerData['visible']; @@ -151,6 +152,7 @@ class FakePlatformGoogleMap { draggable: draggable, visible: visible, infoWindow: infoWindow, + alpha: alpha, )); } diff --git a/packages/google_maps_flutter/test/marker_updates_test.dart b/packages/google_maps_flutter/test/marker_updates_test.dart index cb5731d72875..e208e82e2a96 100644 --- a/packages/google_maps_flutter/test/marker_updates_test.dart +++ b/packages/google_maps_flutter/test/marker_updates_test.dart @@ -75,10 +75,10 @@ void main() { final Marker addedMarker = platformGoogleMap.markersToAdd.first; expect(addedMarker, equals(m2)); + expect(platformGoogleMap.markerIdsToRemove.isEmpty, true); - expect(platformGoogleMap.markersToChange.length, 1); - expect(platformGoogleMap.markersToChange.first, equals(m1)); + expect(platformGoogleMap.markersToChange.isEmpty, true); }); testWidgets("Removing a marker", (WidgetTester tester) async { @@ -175,29 +175,22 @@ void main() { expect(platformGoogleMap.markerIdsToRemove.first, equals(m3.markerId)); }); - testWidgets( - "Partial Update", - (WidgetTester tester) async { - final Marker m1 = Marker(markerId: MarkerId("marker_1")); - Marker m2 = Marker(markerId: MarkerId("marker_2")); - final Set prev = _toSet(m1: m1, m2: m2); - m2 = Marker(markerId: MarkerId("marker_2"), draggable: true); - final Set cur = _toSet(m1: m1, m2: m2); - - await tester.pumpWidget(_mapWithMarkers(prev)); - await tester.pumpWidget(_mapWithMarkers(cur)); - - final FakePlatformGoogleMap platformGoogleMap = - fakePlatformViewsController.lastCreatedView; - - expect(platformGoogleMap.markersToChange, _toSet(m2: m2)); - expect(platformGoogleMap.markerIdsToRemove.isEmpty, true); - expect(platformGoogleMap.markersToAdd.isEmpty, true); - }, - // The test is currently broken due to a bug (we're updating all markers - // instead of just the ones that were changed): - // https://github.com/flutter/flutter/issues/27823 - // TODO(amirh): enable this test when the issue is fixed. - skip: true, - ); + testWidgets("Partial Update", (WidgetTester tester) async { + final Marker m1 = Marker(markerId: MarkerId("marker_1")); + final Marker m2 = Marker(markerId: MarkerId("marker_2")); + Marker m3 = Marker(markerId: MarkerId("marker_3")); + final Set prev = _toSet(m1: m1, m2: m2, m3: m3); + m3 = Marker(markerId: MarkerId("marker_3"), draggable: true); + final Set cur = _toSet(m1: m1, m2: m2, m3: m3); + + await tester.pumpWidget(_mapWithMarkers(prev)); + await tester.pumpWidget(_mapWithMarkers(cur)); + + final FakePlatformGoogleMap platformGoogleMap = + fakePlatformViewsController.lastCreatedView; + + expect(platformGoogleMap.markersToChange, _toSet(m3: m3)); + expect(platformGoogleMap.markerIdsToRemove.isEmpty, true); + expect(platformGoogleMap.markersToAdd.isEmpty, true); + }); } diff --git a/packages/google_maps_flutter/test/polygon_updates_test.dart b/packages/google_maps_flutter/test/polygon_updates_test.dart index 77f096b70484..c666cb687fee 100644 --- a/packages/google_maps_flutter/test/polygon_updates_test.dart +++ b/packages/google_maps_flutter/test/polygon_updates_test.dart @@ -75,10 +75,10 @@ void main() { final Polygon addedPolygon = platformGoogleMap.polygonsToAdd.first; expect(addedPolygon, equals(p2)); + expect(platformGoogleMap.polygonIdsToRemove.isEmpty, true); - expect(platformGoogleMap.polygonsToChange.length, 1); - expect(platformGoogleMap.polygonsToChange.first, equals(p1)); + expect(platformGoogleMap.polygonsToChange.isEmpty, true); }); testWidgets("Removing a polygon", (WidgetTester tester) async { @@ -174,29 +174,22 @@ void main() { expect(platformGoogleMap.polygonIdsToRemove.first, equals(p3.polygonId)); }); - testWidgets( - "Partial Update", - (WidgetTester tester) async { - final Polygon p1 = Polygon(polygonId: PolygonId("polygon_1")); - Polygon p2 = Polygon(polygonId: PolygonId("polygon_2")); - final Set prev = _toSet(p1: p1, p2: p2); - p2 = Polygon(polygonId: PolygonId("polygon_2"), geodesic: true); - final Set cur = _toSet(p1: p1, p2: p2); - - await tester.pumpWidget(_mapWithPolygons(prev)); - await tester.pumpWidget(_mapWithPolygons(cur)); - - final FakePlatformGoogleMap platformGoogleMap = - fakePlatformViewsController.lastCreatedView; - - expect(platformGoogleMap.polygonsToChange, _toSet(p2: p2)); - expect(platformGoogleMap.polygonIdsToRemove.isEmpty, true); - expect(platformGoogleMap.polygonsToAdd.isEmpty, true); - }, - // The test is currently broken due to a bug (we're updating all polygons - // instead of just the ones that were changed): - // https://github.com/flutter/flutter/issues/30764 - // TODO(amirh): enable this test when the issue is fixed. - skip: true, - ); + testWidgets("Partial Update", (WidgetTester tester) async { + final Polygon p1 = Polygon(polygonId: PolygonId("polygon_1")); + final Polygon p2 = Polygon(polygonId: PolygonId("polygon_2")); + Polygon p3 = Polygon(polygonId: PolygonId("polygon_3")); + final Set prev = _toSet(p1: p1, p2: p2, p3: p3); + p3 = Polygon(polygonId: PolygonId("polygon_3"), geodesic: true); + final Set cur = _toSet(p1: p1, p2: p2, p3: p3); + + await tester.pumpWidget(_mapWithPolygons(prev)); + await tester.pumpWidget(_mapWithPolygons(cur)); + + final FakePlatformGoogleMap platformGoogleMap = + fakePlatformViewsController.lastCreatedView; + + expect(platformGoogleMap.polygonsToChange, _toSet(p3: p3)); + expect(platformGoogleMap.polygonIdsToRemove.isEmpty, true); + expect(platformGoogleMap.polygonsToAdd.isEmpty, true); + }); } diff --git a/packages/google_maps_flutter/test/polyline_updates_test.dart b/packages/google_maps_flutter/test/polyline_updates_test.dart index 6946df4c05ee..a0f39185d472 100644 --- a/packages/google_maps_flutter/test/polyline_updates_test.dart +++ b/packages/google_maps_flutter/test/polyline_updates_test.dart @@ -75,10 +75,10 @@ void main() { final Polyline addedPolyline = platformGoogleMap.polylinesToAdd.first; expect(addedPolyline, equals(p2)); + expect(platformGoogleMap.polylineIdsToRemove.isEmpty, true); - expect(platformGoogleMap.polylinesToChange.length, 1); - expect(platformGoogleMap.polylinesToChange.first, equals(p1)); + expect(platformGoogleMap.polylinesToChange.isEmpty, true); }); testWidgets("Removing a polyline", (WidgetTester tester) async { @@ -174,29 +174,22 @@ void main() { expect(platformGoogleMap.polylineIdsToRemove.first, equals(p3.polylineId)); }); - testWidgets( - "Partial Update", - (WidgetTester tester) async { - final Polyline p1 = Polyline(polylineId: PolylineId("polyline_1")); - Polyline p2 = Polyline(polylineId: PolylineId("polyline_2")); - final Set prev = _toSet(p1: p1, p2: p2); - p2 = Polyline(polylineId: PolylineId("polyline_2"), geodesic: true); - final Set cur = _toSet(p1: p1, p2: p2); - - await tester.pumpWidget(_mapWithPolylines(prev)); - await tester.pumpWidget(_mapWithPolylines(cur)); - - final FakePlatformGoogleMap platformGoogleMap = - fakePlatformViewsController.lastCreatedView; - - expect(platformGoogleMap.polylinesToChange, _toSet(p2: p2)); - expect(platformGoogleMap.polylineIdsToRemove.isEmpty, true); - expect(platformGoogleMap.polylinesToAdd.isEmpty, true); - }, - // The test is currently broken due to a bug (we're updating all polylines - // instead of just the ones that were changed): - // https://github.com/flutter/flutter/issues/30764 - // TODO(amirh): enable this test when the issue is fixed. - skip: true, - ); + testWidgets("Partial Update", (WidgetTester tester) async { + final Polyline p1 = Polyline(polylineId: PolylineId("polyline_1")); + final Polyline p2 = Polyline(polylineId: PolylineId("polyline_2")); + Polyline p3 = Polyline(polylineId: PolylineId("polyline_3")); + final Set prev = _toSet(p1: p1, p2: p2, p3: p3); + p3 = Polyline(polylineId: PolylineId("polyline_3"), geodesic: true); + final Set cur = _toSet(p1: p1, p2: p2, p3: p3); + + await tester.pumpWidget(_mapWithPolylines(prev)); + await tester.pumpWidget(_mapWithPolylines(cur)); + + final FakePlatformGoogleMap platformGoogleMap = + fakePlatformViewsController.lastCreatedView; + + expect(platformGoogleMap.polylinesToChange, _toSet(p3: p3)); + expect(platformGoogleMap.polylineIdsToRemove.isEmpty, true); + expect(platformGoogleMap.polylinesToAdd.isEmpty, true); + }); }