-
Notifications
You must be signed in to change notification settings - Fork 4k
[google_maps_flutter] Add onPointOfInterestTap platform implementations #12880
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -38,6 +38,7 @@ | |||||||||||||||||||||||||||||
| import com.google.android.gms.maps.model.MapCapabilities; | ||||||||||||||||||||||||||||||
| import com.google.android.gms.maps.model.MapStyleOptions; | ||||||||||||||||||||||||||||||
| import com.google.android.gms.maps.model.Marker; | ||||||||||||||||||||||||||||||
| import com.google.android.gms.maps.model.PointOfInterest; | ||||||||||||||||||||||||||||||
| import com.google.android.gms.maps.model.Polygon; | ||||||||||||||||||||||||||||||
| import com.google.android.gms.maps.model.Polyline; | ||||||||||||||||||||||||||||||
| import com.google.android.gms.maps.model.TileOverlay; | ||||||||||||||||||||||||||||||
|
|
@@ -385,6 +386,14 @@ public void onCircleClick(Circle circle) { | |||||||||||||||||||||||||||||
| circlesController.onCircleTap(circle.getId()); | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| @Override | ||||||||||||||||||||||||||||||
| public void onPoiClick(PointOfInterest pointOfInterest) { | ||||||||||||||||||||||||||||||
| if (pointOfInterest.placeId != null) { | ||||||||||||||||||||||||||||||
| flutterApi.onPointOfInterestTap( | ||||||||||||||||||||||||||||||
| pointOfInterest.placeId, (Result<Unit> result) -> Unit.INSTANCE); | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
Comment on lines
+389
to
+395
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To prevent a potential
Suggested change
|
||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| @Override | ||||||||||||||||||||||||||||||
| public void onGroundOverlayClick(@NonNull GroundOverlay groundOverlay) { | ||||||||||||||||||||||||||||||
| groundOverlaysController.onGroundOverlayTap(groundOverlay.getId()); | ||||||||||||||||||||||||||||||
|
|
@@ -421,6 +430,7 @@ private void setGoogleMapListener(@Nullable GoogleMapListener listener) { | |||||||||||||||||||||||||||||
| googleMap.setOnPolygonClickListener(listener); | ||||||||||||||||||||||||||||||
| googleMap.setOnPolylineClickListener(listener); | ||||||||||||||||||||||||||||||
| googleMap.setOnCircleClickListener(listener); | ||||||||||||||||||||||||||||||
| googleMap.setOnPoiClickListener(listener); | ||||||||||||||||||||||||||||||
| googleMap.setOnMapClickListener(listener); | ||||||||||||||||||||||||||||||
| googleMap.setOnMapLongClickListener(listener); | ||||||||||||||||||||||||||||||
| googleMap.setOnGroundOverlayClickListener(listener); | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,6 +27,7 @@ | |
| import com.google.android.gms.maps.model.LatLng; | ||
| import com.google.android.gms.maps.model.MapCapabilities; | ||
| import com.google.android.gms.maps.model.Marker; | ||
| import com.google.android.gms.maps.model.PointOfInterest; | ||
| import com.google.maps.android.clustering.ClusterManager; | ||
| import io.flutter.plugin.common.BinaryMessenger; | ||
| import java.util.ArrayList; | ||
|
|
@@ -258,6 +259,28 @@ public void OnClusterItemInfoWindowClickCallsMarkersController() { | |
| verify(mockMarkersController, times(1)).onClusterItemInfoWindowTap(markerBuilder.markerId()); | ||
| } | ||
|
|
||
| @Test | ||
| public void OnPoiClickCallsFlutterApi() { | ||
| GoogleMapController googleMapController = getGoogleMapControllerWithMockedDependencies(); | ||
| googleMapController.onMapReady(mockGoogleMap); | ||
|
|
||
| PointOfInterest pointOfInterest = | ||
| new PointOfInterest(new LatLng(0, 0), "place-123", "Test Place"); | ||
| googleMapController.onPoiClick(pointOfInterest); | ||
|
|
||
| verify(flutterApi, times(1)).onPointOfInterestTap(eq("place-123"), any()); | ||
| } | ||
|
|
||
| @Test | ||
| public void OnPoiClickNullPlaceIdDoesNotCallFlutterApi() { | ||
| GoogleMapController googleMapController = getGoogleMapControllerWithMockedDependencies(); | ||
| googleMapController.onMapReady(mockGoogleMap); | ||
|
|
||
| googleMapController.onPoiClick(new PointOfInterest(new LatLng(0, 0), null, "Test Place")); | ||
|
|
||
| verify(flutterApi, times(0)).onPointOfInterestTap(any(), any()); | ||
| } | ||
|
Comment on lines
+274
to
+282
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add a unit test to verify that @Test
public void OnPoiClickNullPlaceIdDoesNotCallFlutterApi() {
GoogleMapController googleMapController = getGoogleMapControllerWithMockedDependencies();
googleMapController.onMapReady(mockGoogleMap);
googleMapController.onPoiClick(new PointOfInterest(new LatLng(0, 0), null, "Test Place"));
verify(flutterApi, times(0)).onPointOfInterestTap(any(), any());
}
@Test
public void OnPoiClickNullPoiDoesNotCallFlutterApi() {
GoogleMapController googleMapController = getGoogleMapControllerWithMockedDependencies();
googleMapController.onMapReady(mockGoogleMap);
googleMapController.onPoiClick(null);
verify(flutterApi, times(0)).onPointOfInterestTap(any(), any());
} |
||
|
|
||
| @Test | ||
| public void SetInitialHeatmaps() { | ||
| GoogleMapController googleMapController = getGoogleMapControllerWithMockedDependencies(); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To prevent potential
NullPointerExceptions, it is safer to perform a null check onpointOfInterestbefore accessing its properties, especially since it is a parameter received from an external SDK and Java does not have compile-time null safety.