Skip to content

Commit 5bec448

Browse files
ppicasmormih
authored andcommitted
[google_maps_flutter] Avoid unnecessary redraws (flutter#1933)
1 parent 853277c commit 5bec448

16 files changed

Lines changed: 166 additions & 113 deletions

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,4 @@ Audrius Karosevicius <audrius.karosevicius@gmail.com>
4343
Lukasz Piliszczuk <lukasz@intheloup.io>
4444
SoundReply Solutions GmbH <ch@soundreply.com>
4545
Rafal Wachol <rwachol@gmail.com>
46+
Pau Picas <pau.picas@gmail.com>

packages/google_maps_flutter/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.5.21
2+
3+
* Don't recreate map elements if they didn't change since last widget build.
4+
15
## 0.5.20+6
26

37
* Adds support for toggling the traffic layer

packages/google_maps_flutter/lib/src/circle.dart

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,16 @@ class Circle {
141141
if (identical(this, other)) return true;
142142
if (other.runtimeType != runtimeType) return false;
143143
final Circle typedOther = other;
144-
return circleId == typedOther.circleId;
144+
return circleId == typedOther.circleId &&
145+
consumeTapEvents == typedOther.consumeTapEvents &&
146+
fillColor == typedOther.fillColor &&
147+
center == typedOther.center &&
148+
radius == typedOther.radius &&
149+
strokeColor == typedOther.strokeColor &&
150+
strokeWidth == typedOther.strokeWidth &&
151+
visible == typedOther.visible &&
152+
zIndex == typedOther.zIndex &&
153+
onTap == typedOther.onTap;
145154
}
146155

147156
@override

packages/google_maps_flutter/lib/src/circle_updates.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,17 @@ class _CircleUpdates {
3636
.map(idToCurrentCircle)
3737
.toSet();
3838

39+
/// Returns `true` if [current] is not equals to previous one with the
40+
/// same id.
41+
bool hasChanged(Circle current) {
42+
final Circle previous = previousCircles[current.circleId];
43+
return current != previous;
44+
}
45+
3946
final Set<Circle> _circlesToChange = currentCircleIds
4047
.intersection(prevCircleIds)
4148
.map(idToCurrentCircle)
49+
.where(hasChanged)
4250
.toSet();
4351

4452
circlesToAdd = _circlesToAdd;

packages/google_maps_flutter/lib/src/marker.dart

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,19 @@ class Marker {
283283
if (identical(this, other)) return true;
284284
if (other.runtimeType != runtimeType) return false;
285285
final Marker typedOther = other;
286-
return markerId == typedOther.markerId;
286+
return markerId == typedOther.markerId &&
287+
alpha == typedOther.alpha &&
288+
anchor == typedOther.anchor &&
289+
consumeTapEvents == typedOther.consumeTapEvents &&
290+
draggable == typedOther.draggable &&
291+
flat == typedOther.flat &&
292+
icon == typedOther.icon &&
293+
infoWindow == typedOther.infoWindow &&
294+
position == typedOther.position &&
295+
rotation == typedOther.rotation &&
296+
visible == typedOther.visible &&
297+
zIndex == typedOther.zIndex &&
298+
onTap == typedOther.onTap;
287299
}
288300

289301
@override

packages/google_maps_flutter/lib/src/marker_updates.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,17 @@ class _MarkerUpdates {
3636
.map(idToCurrentMarker)
3737
.toSet();
3838

39+
/// Returns `true` if [current] is not equals to previous one with the
40+
/// same id.
41+
bool hasChanged(Marker current) {
42+
final Marker previous = previousMarkers[current.markerId];
43+
return current != previous;
44+
}
45+
3946
final Set<Marker> _markersToChange = currentMarkerIds
4047
.intersection(prevMarkerIds)
4148
.map(idToCurrentMarker)
49+
.where(hasChanged)
4250
.toSet();
4351

4452
markersToAdd = _markersToAdd;

packages/google_maps_flutter/lib/src/polygon.dart

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,16 @@ class Polygon {
150150
if (identical(this, other)) return true;
151151
if (other.runtimeType != runtimeType) return false;
152152
final Polygon typedOther = other;
153-
return polygonId == typedOther.polygonId;
153+
return polygonId == typedOther.polygonId &&
154+
consumeTapEvents == typedOther.consumeTapEvents &&
155+
fillColor == typedOther.fillColor &&
156+
geodesic == typedOther.geodesic &&
157+
listEquals(points, typedOther.points) &&
158+
visible == typedOther.visible &&
159+
strokeColor == typedOther.strokeColor &&
160+
strokeWidth == typedOther.strokeWidth &&
161+
zIndex == typedOther.zIndex &&
162+
onTap == typedOther.onTap;
154163
}
155164

156165
@override

packages/google_maps_flutter/lib/src/polygon_updates.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,17 @@ class _PolygonUpdates {
3636
.map(idToCurrentPolygon)
3737
.toSet();
3838

39+
/// Returns `true` if [current] is not equals to previous one with the
40+
/// same id.
41+
bool hasChanged(Polygon current) {
42+
final Polygon previous = previousPolygons[current.polygonId];
43+
return current != previous;
44+
}
45+
3946
final Set<Polygon> _polygonsToChange = currentPolygonIds
4047
.intersection(prevPolygonIds)
4148
.map(idToCurrentPolygon)
49+
.where(hasChanged)
4250
.toSet();
4351

4452
polygonsToAdd = _polygonsToAdd;

packages/google_maps_flutter/lib/src/polyline.dart

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,19 @@ class Polyline {
192192
if (identical(this, other)) return true;
193193
if (other.runtimeType != runtimeType) return false;
194194
final Polyline typedOther = other;
195-
return polylineId == typedOther.polylineId;
195+
return polylineId == typedOther.polylineId &&
196+
consumeTapEvents == typedOther.consumeTapEvents &&
197+
color == typedOther.color &&
198+
geodesic == typedOther.geodesic &&
199+
jointType == typedOther.jointType &&
200+
listEquals(patterns, typedOther.patterns) &&
201+
listEquals(points, typedOther.points) &&
202+
startCap == typedOther.startCap &&
203+
endCap == typedOther.endCap &&
204+
visible == typedOther.visible &&
205+
width == typedOther.width &&
206+
zIndex == typedOther.zIndex &&
207+
onTap == typedOther.onTap;
196208
}
197209

198210
@override

packages/google_maps_flutter/lib/src/polyline_updates.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,17 @@ class _PolylineUpdates {
3838
.map(idToCurrentPolyline)
3939
.toSet();
4040

41+
/// Returns `true` if [current] is not equals to previous one with the
42+
/// same id.
43+
bool hasChanged(Polyline current) {
44+
final Polyline previous = previousPolylines[current.polylineId];
45+
return current != previous;
46+
}
47+
4148
final Set<Polyline> _polylinesToChange = currentPolylineIds
4249
.intersection(prevPolylineIds)
4350
.map(idToCurrentPolyline)
51+
.where(hasChanged)
4452
.toSet();
4553

4654
polylinesToAdd = _polylinesToAdd;

0 commit comments

Comments
 (0)