-
Notifications
You must be signed in to change notification settings - Fork 3.9k
[google_maps_flutter] Add onPointOfInterestTap callback #11872
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 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 |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| // 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/widgets.dart'; | ||
| import 'package:flutter_test/flutter_test.dart'; | ||
| import 'package:google_maps_flutter/google_maps_flutter.dart'; | ||
| import 'package:google_maps_flutter_platform_interface/google_maps_flutter_platform_interface.dart'; | ||
|
|
||
| import 'fake_google_maps_flutter_platform.dart'; | ||
|
|
||
| void main() { | ||
| TestWidgetsFlutterBinding.ensureInitialized(); | ||
| late FakeGoogleMapsFlutterPlatform platform; | ||
|
|
||
| setUp(() { | ||
| platform = FakeGoogleMapsFlutterPlatform(); | ||
| GoogleMapsFlutterPlatform.instance = platform; | ||
| }); | ||
|
|
||
| testWidgets('onPointOfInterestTap callback receives place ID from platform event', ( | ||
| WidgetTester tester, | ||
| ) async { | ||
| PointOfInterestId? tappedPointOfInterestId; | ||
|
|
||
| await tester.pumpWidget( | ||
| Directionality( | ||
| textDirection: TextDirection.ltr, | ||
| child: GoogleMap( | ||
| initialCameraPosition: const CameraPosition(target: LatLng(0.0, 0.0)), | ||
| onPointOfInterestTap: (PointOfInterestId pointOfInterestId) { | ||
| tappedPointOfInterestId = pointOfInterestId; | ||
| }, | ||
| ), | ||
| ), | ||
| ); | ||
|
|
||
| await tester.pump(); | ||
|
|
||
| expect(platform.createdIds, isNotEmpty); | ||
| final int mapId = platform.createdIds.first; | ||
|
|
||
| platform.mapEventStreamController.add( | ||
| PointOfInterestTapEvent(mapId, const PointOfInterestId('place-123')), | ||
| ); | ||
|
|
||
| await tester.pump(); | ||
|
|
||
| expect(tappedPointOfInterestId, const PointOfInterestId('place-123')); | ||
| }); | ||
| } |
| 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
+390
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. Defensively checking
Suggested change
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. The
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. Fair enough. |
||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| @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); | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.