-
Notifications
You must be signed in to change notification settings - Fork 3.6k
[google_maps_flutter] Add onPoiTap callback to GoogleMap #10963
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
base: main
Are you sure you want to change the base?
[google_maps_flutter] Add onPoiTap callback to GoogleMap #10963
Conversation
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.
Code Review
This pull request introduces the onPoiTap callback to the GoogleMap widget, allowing developers to handle user taps on points of interest on the map. The feature is implemented across the platform interface, Android, and iOS, with corresponding updates to the example application and tests. The changes involve adding new event types, updating platform-specific listeners, and exposing the new callback in the app-facing widget. My review includes suggestions for improving code clarity, test robustness, and fixing a critical dependency issue.
| flutter: | ||
| sdk: flutter | ||
| google_maps_flutter_platform_interface: ^2.13.0 | ||
| google_maps_flutter_platform_interface: ^2.14.0 |
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.
The google_maps_flutter_platform_interface version should be ^2.15.0 to match the version in which onPoiTap support was added. The current version ^2.14.0 will cause dependency conflicts or build failures since this package uses types introduced in 2.15.0.
google_maps_flutter_platform_interface: ^2.15.0
packages/google_maps_flutter/google_maps_flutter/example/lib/place_poi.dart
Outdated
Show resolved
Hide resolved
| import 'package:google_maps_flutter_android/google_maps_flutter_android.dart'; | ||
| import 'package:google_maps_flutter_platform_interface/google_maps_flutter_platform_interface.dart'; | ||
|
|
||
| import 'package:google_maps_flutter_platform_interface/google_maps_flutter_platform_interface.dart'; |
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.
| Log.e("POI_TEST", "Native POI Click Detected: " + poi.name); | ||
| Log.e("POI_TEST", "Native Tap! Sending to Channel ID: " + id); |
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.
| public void onPoiClick_SendsMethodCall() { | ||
| PointOfInterest poi = new PointOfInterest(new LatLng(1.0, 2.0), "placeId", "name"); | ||
|
|
||
| // controller is the instance of GoogleMapController in your test file | ||
| controller.onPoiClick(poi); | ||
|
|
||
| // Verify the messenger sent the message to the correct channel | ||
| verify(binaryMessenger).send( | ||
| eq("plugins.flutter.io/google_maps_0"), | ||
| any(ByteBuffer.class), | ||
| any(BinaryMessenger.BinaryReply.class)); | ||
| } |
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.
This test only verifies that a message is sent on the binary messenger, but it doesn't check the content of the message. A more robust test would be to use a mock MapsCallbackApi and verify that onPoiTap is called with the correct data. This ensures that the data is correctly constructed and passed to the Pigeon API.
Here's an example of how you could improve it:
@Test
public void onPoiClick_sendsCorrectData() {
// Assuming 'controller' and 'flutterApi' are set up as in other tests.
PointOfInterest poi = new PointOfInterest(new LatLng(1.0, 2.0), "placeId", "name");
controller.onPoiClick(poi);
ArgumentCaptor<Messages.PlatformPointOfInterest> poiCaptor = ArgumentCaptor.forClass(Messages.PlatformPointOfInterest.class);
verify(flutterApi).onPoiTap(poiCaptor.capture(), any(Messages.VoidResult.class));
Messages.PlatformPointOfInterest capturedPoi = poiCaptor.getValue();
assertEquals("name", capturedPoi.getName());
assertEquals("placeId", capturedPoi.getPlaceId());
assertEquals(1.0, capturedPoi.getPosition().getLatitude(), 1e-6);
assertEquals(2.0, capturedPoi.getPosition().getLongitude(), 1e-6);
}| /// Callback method for when a [PointOfInterest] is tapped. | ||
| typedef POIClickCallback = void Function(PointOfInterest poi); |
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.
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
stuartmorgan-g
left a comment
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.
Thanks for the contribution!
- I read the [Contributor Guide] and followed the process outlined there for submitting PRs.
This needs to follow our documented process for changing federated plugins, so that CI works.
Please also be sure to review the feedback on the previous PR, especially this comment, and update accordingly. Even if this PR doesn't include web support (although it would be preferable if it did, especially since there is a previous PR to draw on), it does need to be designed in such a way as to not cause this problem for web later.
| ), | ||
| ); | ||
|
|
||
| // 🔥 IMPORTANT: Wait for the map initialization (onMapCreated) to complete |
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.
Please follow our standard commenting style. Sentences should be properly punctuated, and we don't use emoji in comments.
| ); | ||
|
|
||
| // 🔥 IMPORTANT: Wait for the map initialization (onMapCreated) to complete | ||
| await tester.pumpAndSettle(); |
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.
pumpAndSettle is for waiting for rendering to complete, not for arbitrary specific tasks. The way to wait for onMapCreated to complete is to have a future that completes when onMapCreated is called, and then wait for that. It is important that tests not be flaky because they are using delays as a proxy for waiting for specific conditions.
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.
Please review the package again. I have done the following works:
- Revamped the code as per the review of @stuartmorgan-g and @gemini_code_assist
- Added Support for flutter web for onPoiTap Callback
- Added Integration test for onPoiTap
- Updated Version for the google_maps_flutter_web package
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.
Thank you for addressing the feedback regarding the pumpAndSettle usage. The updated test now correctly waits for onMapCreated to complete using a Completer, which is a much more robust approach.
…ssage content being passed rather than the detecting if a binary message is being sent
…imRoyChowdhury/packages into feature/google-maps-poi-click
4512a35 to
3079afc
Compare
stuartmorgan-g
left a comment
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.
I've left some initial feedback.
This is not the first time I've had to point out that previous feedback has not been addressed. Please ensure that you either address feedback, or ask for clarification if necessary, before requesting review again.
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.
Generated files should never be patched or reconciled in merges, they should be regenerated from the source. These files should absolutely not be part of the PR, but the fact that they existed locally suggests that you haven't ensured up-to-date generated output.
| final Set<ClusterManager> clusterManagers; | ||
|
|
||
| /// Callback for Point of Interests tap | ||
| final ArgumentCallback<PointOfInterest>? onPoiTap; |
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.
This needs to be grouped with, and following the same comment style as, all the other callbacks.
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.
This change should have corresponding native unit tests.
|
|
||
| /// A [PointOfInterest] has been tapped. | ||
| Stream<MapPoiTapEvent> onPoiTap({required int mapId}) { | ||
| throw UnimplementedError('onPoiTap() has not been implemented.'); |
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.
This should return an empty stream, not throw, to avoid breaking existing implementations.
| final Set<ClusterManager> clusterManagers; | ||
|
|
||
| /// Callback for Point of Interests tap | ||
| final ArgumentCallback<PointOfInterest>? onPoiTap; |
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.
My previous comment has not been addressed. This is still returning an inflated POI rather than an ID.
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.
Code Review
This pull request introduces onPoiTap support for the GoogleMap widget, enabling tap detection on Points of Interest across Android, iOS, and web. The changes are well-implemented, touching the platform interface, all three platform implementations, and adding a new example page with tests. My review includes a minor code simplification suggestion and points out several patch-related artifact files that should be removed to maintain repository cleanliness. Overall, this is a great feature addition.
| @@ -0,0 +1,11 @@ | |||
| --- packages/google_maps_flutter/google_maps_flutter_android/example/lib/example_google_map.dart | |||
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.
| @@ -0,0 +1,1574 @@ | |||
| --- packages/google_maps_flutter/google_maps_flutter_android/lib/src/messages.g.dart | |||
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.
| @@ -0,0 +1,901 @@ | |||
| // Copyright 2013 The Flutter Authors | |||
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.
| @@ -0,0 +1,807 @@ | |||
| --- packages/google_maps_flutter/google_maps_flutter_ios/ios/google_maps_flutter_ios/Sources/google_maps_flutter_ios/include/google_maps_flutter_ios/google_maps_flutter_pigeon_messages.g.h | |||
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.
| @@ -0,0 +1,1496 @@ | |||
| --- packages/google_maps_flutter/google_maps_flutter_ios/lib/src/messages.g.dart | |||
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.
| if (widget.onPoiTap != null) { | ||
| widget.onPoiTap!(poi); | ||
| } |
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.
…s, formatting and removed name from PointOfInterest Model
This PR adds support for detecting taps on the base map's Points of Interest.
Issue: Fixes flutter/flutter#60695
Changes:
Fixes: N/A - This is a new feature.
Pre-Review Checklist
[shared_preferences]pubspec.yamlwith an appropriate new version according to the [pub versioning philosophy], or I have commented below to indicate which [version change exemption] this PR falls under[^1].CHANGELOG.mdto add a description of the change, [following repository CHANGELOG style], or I have commented below to indicate which [CHANGELOG exemption] this PR falls under[^1].///).