-
Notifications
You must be signed in to change notification settings - Fork 3.7k
[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?
Changes from 37 commits
11cc8c9
18d0e19
fa00c6a
ca71a07
a28a4db
2aa24ed
3c8b5b6
d54f1b3
904a092
7b8f809
e8d0682
752925f
69ecb49
8e522fa
ae2a1ea
7552d23
3145ae7
4e0803e
2382ad4
5781bdc
347d0a9
ece8e5c
a250736
a10dbdb
cdabd12
689a05e
aa9f696
5aea2d0
a58d87c
70c2e69
7c7c0db
cfd44c5
5fab785
72f43f3
3079afc
9b17699
7596469
9cc391e
28b709b
2589982
5acc132
9d9139c
b57aba0
679b64f
f7cd0a2
f1480dd
89450b3
d0f16d6
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 |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| // Copyright 2013 The Flutter Authors | ||
| // Use of this source code is governed by a BSD-style license that can be | ||
| // found in the LICENSE file. | ||
|
|
||
| import 'package:flutter/material.dart'; | ||
| import 'package:google_maps_flutter/google_maps_flutter.dart'; | ||
|
|
||
| import 'page.dart'; | ||
|
|
||
| /// Page for demonstrating Point of Interest (POI) tapping. | ||
| class PlacePoiPage extends GoogleMapExampleAppPage { | ||
| /// Default constructor. | ||
| const PlacePoiPage({super.key}) | ||
| : super(const Icon(Icons.business), 'Place POI'); | ||
|
|
||
| @override | ||
| Widget build(BuildContext context) { | ||
| return const PlacePoiBody(); | ||
| } | ||
| } | ||
|
|
||
| /// Body of the POI page. | ||
| class PlacePoiBody extends StatefulWidget { | ||
| /// Default constructor. | ||
| const PlacePoiBody({super.key}); | ||
|
|
||
| @override | ||
| State<StatefulWidget> createState() => PlacePoiBodyState(); | ||
| } | ||
|
|
||
| /// State for [PlacePoiBody]. | ||
| class PlacePoiBodyState extends State<PlacePoiBody> { | ||
| /// The controller for the map. | ||
| /// | ||
| /// This is public to match the example pattern, but marked with a doc comment. | ||
| GoogleMapController? controller; | ||
| PointOfInterest? _lastPoi; | ||
|
|
||
| final CameraPosition _kKolkata = const CameraPosition( | ||
| target: LatLng(22.54222641620606, 88.34560669761545), | ||
| zoom: 16.0, | ||
| ); | ||
|
|
||
| // ignore: use_setters_to_change_properties | ||
| void _onMapCreated(GoogleMapController controller) { | ||
| this.controller = controller; | ||
| } | ||
|
|
||
| void _onPoiTap(PointOfInterest poi) { | ||
| setState(() { | ||
| _lastPoi = poi; | ||
| }); | ||
|
|
||
| controller?.animateCamera(CameraUpdate.newLatLng(poi.position)); | ||
| } | ||
|
|
||
| @override | ||
| Widget build(BuildContext context) { | ||
| return Column( | ||
| children: <Widget>[ | ||
| Expanded( | ||
| child: GoogleMap( | ||
| onMapCreated: _onMapCreated, | ||
| initialCameraPosition: _kKolkata, | ||
| onPoiTap: _onPoiTap, | ||
| myLocationButtonEnabled: false, | ||
| ), | ||
| ), | ||
| Container( | ||
| color: Colors.white, | ||
| width: double.infinity, | ||
| padding: const EdgeInsets.all(16.0), | ||
| child: Column( | ||
| crossAxisAlignment: CrossAxisAlignment.start, | ||
| mainAxisSize: MainAxisSize.min, | ||
| children: <Widget>[ | ||
| const Text( | ||
| 'Last Tapped POI:', | ||
| style: TextStyle(fontWeight: FontWeight.bold, fontSize: 16), | ||
| ), | ||
| const SizedBox(height: 8), | ||
| if (_lastPoi != null) ...<Widget>[ | ||
| Text('Name: ${_lastPoi!.name ?? "Unknown"}'), | ||
| Text('Place ID: ${_lastPoi!.placeId}'), | ||
| Text( | ||
| 'Lat/Lng: ${_lastPoi!.position.latitude.toStringAsFixed(5)}, ${_lastPoi!.position.longitude.toStringAsFixed(5)}', | ||
| ), | ||
| ] else | ||
| const Text('Tap on a business or landmark icon...'), | ||
| ], | ||
| ), | ||
| ), | ||
| ], | ||
| ); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -133,6 +133,7 @@ class GoogleMap extends StatefulWidget { | |
| this.onCameraIdle, | ||
| this.onTap, | ||
| this.onLongPress, | ||
| this.onPoiTap, | ||
| this.cloudMapId, | ||
| }); | ||
|
|
||
|
|
@@ -235,6 +236,9 @@ class GoogleMap extends StatefulWidget { | |
| /// See https://pub.dev/packages/google_maps_flutter_web. | ||
| final Set<ClusterManager> clusterManagers; | ||
|
|
||
| /// Callback for Point of Interests tap | ||
| final ArgumentCallback<PointOfInterest>? onPoiTap; | ||
|
Collaborator
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. My previous comment has not been addressed. This is still returning an inflated POI rather than an ID. |
||
|
|
||
| /// Ground overlays to be initialized for the map. | ||
| /// | ||
| /// Support table for Ground Overlay features: | ||
|
|
@@ -612,6 +616,12 @@ class _GoogleMapState extends State<GoogleMap> { | |
| } | ||
| } | ||
|
|
||
| void onPoiTap(PointOfInterest poi) { | ||
| if (widget.onPoiTap != null) { | ||
| widget.onPoiTap!(poi); | ||
| } | ||
|
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.
Author
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. @stuartmorgan-g can you please see the code changes again. I have removed the name param from the onPoiTap. As you said that it sent inflated POI values in the web version. In the web version the name is not there in the native implementation which is why the inflated values were returned that's why I have removed the name param from all platform implementations and kept only the placeId and position. As the unimplemented error was thrown which would have resulted in a breaking change so I have changed it to return an empty string instead of throwing. I also applied the make-deps-path-based tooling but it was resulting in blank dependency overrides so I had to add the dependency overrides manually. Please help me in understanding this if I am using the tool incorrectly. Above all thank you for your constant valuable feedback on the errors I was doing continuously, it would be great if you explain more about the errors if those happen again, and I have read the documentation regarding the federated plugin change and did all what I understood, please guide me if I have left something unaddressed.
Collaborator
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.
It appears that you have removed the name from the The issue is not that POI doesn't have a name on web, it's that the tap event callback doesn't return a POI on web. That can't be fixed by removing information from POI itself. It needs to be solved by having the tap handler receive something that is not the POI class.
Author
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. @stuartmorgan-g Thank you for the clarification. That makes perfect sense regarding not removing data from the core PointOfInterest class. Before I write the code and push another combination PR, I want to make sure my planned architecture aligns exactly with your expectations:
Does this separation between the core POI class and the tap event payload resolve the issue?
Collaborator
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. My expectation is that you follow the architecture laid out in the comment I have referred you to several times, which is not what you just described. Before I spend more of my time on this review, I would like a clear, explicit answer to my previous question about how you are using AI here, and how much human involvement there is.
Author
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. @stuartmorgan-g Thank you for your time and patience. I am trying to grasp on the architecture that you have referred in the comments. I have used AI to learn about the CI errors I was going through and therefore trying my best to contribute to the package.
Collaborator
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.
A key point is this section of the comment:
An event payload class that has auto-hydrated POI data (such as a |
||
| } | ||
|
|
||
| void onPolygonTap(PolygonId polygonId) { | ||
| final Polygon? polygon = _polygons[polygonId]; | ||
| if (polygon == null) { | ||
|
|
||
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.