Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,4 @@ Audrius Karosevicius <[email protected]>
Lukasz Piliszczuk <[email protected]>
SoundReply Solutions GmbH <[email protected]>
Rafal Wachol <[email protected]>
Pau Picas <[email protected]>
4 changes: 4 additions & 0 deletions packages/google_maps_flutter/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
11 changes: 10 additions & 1 deletion packages/google_maps_flutter/lib/src/circle.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions packages/google_maps_flutter/lib/src/circle_updates.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<Circle> _circlesToChange = currentCircleIds
.intersection(prevCircleIds)
.map(idToCurrentCircle)
.where(hasChanged)
.toSet();

circlesToAdd = _circlesToAdd;
Expand Down
14 changes: 13 additions & 1 deletion packages/google_maps_flutter/lib/src/marker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions packages/google_maps_flutter/lib/src/marker_updates.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<Marker> _markersToChange = currentMarkerIds
.intersection(prevMarkerIds)
.map(idToCurrentMarker)
.where(hasChanged)
.toSet();

markersToAdd = _markersToAdd;
Expand Down
11 changes: 10 additions & 1 deletion packages/google_maps_flutter/lib/src/polygon.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions packages/google_maps_flutter/lib/src/polygon_updates.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<Polygon> _polygonsToChange = currentPolygonIds
.intersection(prevPolygonIds)
.map(idToCurrentPolygon)
.where(hasChanged)
.toSet();

polygonsToAdd = _polygonsToAdd;
Expand Down
14 changes: 13 additions & 1 deletion packages/google_maps_flutter/lib/src/polyline.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions packages/google_maps_flutter/lib/src/polyline_updates.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<Polyline> _polylinesToChange = currentPolylineIds
.intersection(prevPolylineIds)
.map(idToCurrentPolyline)
.where(hasChanged)
.toSet();

polylinesToAdd = _polylinesToAdd;
Expand Down
2 changes: 1 addition & 1 deletion packages/google_maps_flutter/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: google_maps_flutter
description: A Flutter plugin for integrating Google Maps in iOS and Android applications.
author: Flutter Team <[email protected]>
homepage: https://github.com/flutter/plugins/tree/master/packages/google_maps_flutter
version: 0.5.20+6
version: 0.5.21

dependencies:
flutter:
Expand Down
47 changes: 20 additions & 27 deletions packages/google_maps_flutter/test/circle_updates_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@ void main() {

final Circle addedCircle = platformGoogleMap.circlesToAdd.first;
expect(addedCircle, equals(c2));

expect(platformGoogleMap.circleIdsToRemove.isEmpty, true);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think having a test with multiple circles, where we only change a couple of them and compute the updates would be interesting. Same for others too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, I'll will add some tests.

expect(platformGoogleMap.circlesToChange.length, 1);
expect(platformGoogleMap.circlesToChange.first, equals(c1));
expect(platformGoogleMap.circlesToChange.isEmpty, true);
});

testWidgets("Removing a circle", (WidgetTester tester) async {
Expand Down Expand Up @@ -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<Circle> prev = _toSet(c1: c1, c2: c2);
c2 = Circle(circleId: CircleId("circle_2"), radius: 10);
final Set<Circle> 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<Circle> prev = _toSet(c1: c1, c2: c2, c3: c3);
c3 = Circle(circleId: CircleId("circle_3"), radius: 10);
final Set<Circle> 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);
});
}
2 changes: 2 additions & 0 deletions packages/google_maps_flutter/test/fake_maps_controllers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ class FakePlatformGoogleMap {
final Set<Marker> result = Set<Marker>();
for (Map<dynamic, dynamic> markerData in markersData) {
final String markerId = markerData['markerId'];
final double alpha = markerData['alpha'];
final bool draggable = markerData['draggable'];
final bool visible = markerData['visible'];

Expand All @@ -151,6 +152,7 @@ class FakePlatformGoogleMap {
draggable: draggable,
visible: visible,
infoWindow: infoWindow,
alpha: alpha,
));
}

Expand Down
47 changes: 20 additions & 27 deletions packages/google_maps_flutter/test/marker_updates_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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<Marker> prev = _toSet(m1: m1, m2: m2);
m2 = Marker(markerId: MarkerId("marker_2"), draggable: true);
final Set<Marker> 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<Marker> prev = _toSet(m1: m1, m2: m2, m3: m3);
m3 = Marker(markerId: MarkerId("marker_3"), draggable: true);
final Set<Marker> 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);
});
}
47 changes: 20 additions & 27 deletions packages/google_maps_flutter/test/polygon_updates_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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<Polygon> prev = _toSet(p1: p1, p2: p2);
p2 = Polygon(polygonId: PolygonId("polygon_2"), geodesic: true);
final Set<Polygon> 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<Polygon> prev = _toSet(p1: p1, p2: p2, p3: p3);
p3 = Polygon(polygonId: PolygonId("polygon_3"), geodesic: true);
final Set<Polygon> 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);
});
}
Loading