From 102747a9c6cecb79c27c11f6ee333a23a65e82bb Mon Sep 17 00:00:00 2001
From: Pau Picas
Date: Fri, 20 Sep 2019 16:13:28 +0200
Subject: [PATCH] [google_maps_flutter] Clone cached elements in GoogleMap
Create a clone of cached elements in GoogleMap (Polyline, Polygon, etc.)
to detect modifications if these objects are mutated instead of
modified by copy.
---
packages/google_maps_flutter/CHANGELOG.md | 5 +++++
.../google_maps_flutter/lib/src/circle.dart | 7 +++++--
.../google_maps_flutter/lib/src/marker.dart | 7 +++++--
.../google_maps_flutter/lib/src/polygon.dart | 7 ++++++-
.../google_maps_flutter/lib/src/polyline.dart | 13 +++++++++++--
packages/google_maps_flutter/pubspec.yaml | 2 +-
.../test/fake_maps_controllers.dart | 10 ++++++++++
.../test/polygon_updates_test.dart | 19 +++++++++++++++++++
.../test/polyline_updates_test.dart | 19 +++++++++++++++++++
9 files changed, 81 insertions(+), 8 deletions(-)
diff --git a/packages/google_maps_flutter/CHANGELOG.md b/packages/google_maps_flutter/CHANGELOG.md
index 56fbf0ee4a6e..45ecfbeb3e3d 100644
--- a/packages/google_maps_flutter/CHANGELOG.md
+++ b/packages/google_maps_flutter/CHANGELOG.md
@@ -1,3 +1,8 @@
+## 0.5.21+7
+
+* Create a clone of cached elements in GoogleMap (Polyline, Polygon, etc.) to detect modifications
+ if these objects are mutated instead of modified by copy.
+
## 0.5.21+6
* Override a default method to work around flutter/flutter#40126.
diff --git a/packages/google_maps_flutter/lib/src/circle.dart b/packages/google_maps_flutter/lib/src/circle.dart
index eefb8c021fa6..1ab966cc6957 100644
--- a/packages/google_maps_flutter/lib/src/circle.dart
+++ b/packages/google_maps_flutter/lib/src/circle.dart
@@ -114,6 +114,9 @@ class Circle {
);
}
+ /// Creates a new [Circle] object whose values are the same as this instance.
+ Circle clone() => copyWith();
+
dynamic _toJson() {
final Map json = {};
@@ -161,8 +164,8 @@ Map _keyByCircleId(Iterable circles) {
if (circles == null) {
return {};
}
- return Map.fromEntries(circles.map(
- (Circle circle) => MapEntry(circle.circleId, circle)));
+ return Map.fromEntries(circles.map((Circle circle) =>
+ MapEntry(circle.circleId, circle.clone())));
}
List