Skip to content
Closed
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
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## NEXT
## 2.19.0

* Adds support for tapping points of interest on the map.
On iOS, this requires `google_maps_flutter_ios_sdk9` or
`google_maps_flutter_ios_sdk10` (the default `google_maps_flutter_ios`
package does not receive new features).
* Updates minimum supported SDK version to Flutter 3.41/Dart 3.11.

## 2.18.1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class _MapClickBodyState extends State<_MapClickBody> {
GoogleMapController? mapController;
LatLng? _lastTap;
LatLng? _lastLongPress;
String? _lastPointOfInterestPlaceId;

@override
Widget build(BuildContext context) {
Expand All @@ -51,6 +52,11 @@ class _MapClickBodyState extends State<_MapClickBody> {
_lastLongPress = pos;
});
},
onPointOfInterestTap: (PointOfInterestId pointOfInterestId) {
setState(() {
_lastPointOfInterestPlaceId = pointOfInterestId.value;
});
},
);

final columnChildren = <Widget>[
Expand All @@ -73,6 +79,17 @@ class _MapClickBodyState extends State<_MapClickBody> {
child: Text(_lastLongPress != null ? 'Long pressed' : '', textAlign: TextAlign.center),
),
);
final lastPointOfInterestTap =
'Point of interest place ID:\n${_lastPointOfInterestPlaceId ?? ""}';
columnChildren.add(Center(child: Text(lastPointOfInterestTap, textAlign: TextAlign.center)));
columnChildren.add(
Center(
child: Text(
_lastPointOfInterestPlaceId != null ? 'Point of interest tapped' : '',
textAlign: TextAlign.center,
),
),
);
}
return Column(crossAxisAlignment: CrossAxisAlignment.stretch, children: columnChildren);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ dependencies:
# The example app is bundled with the plugin so we use a path dependency on
# the parent directory to use the current plugin's version.
path: ../
google_maps_flutter_android: ^2.19.1
google_maps_flutter_platform_interface: ^2.16.0
google_maps_flutter_android: ^2.20.0
google_maps_flutter_platform_interface: ^2.17.0

dev_dependencies:
build_runner: ^2.1.10
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export 'package:google_maps_flutter_platform_interface/google_maps_flutter_platf
MinMaxZoomPreference,
PatternItem,
PinConfig,
PointOfInterestId,
Polygon,
PolygonId,
Polyline,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,11 @@ class GoogleMapController {
.onLongPress(mapId: mapId)
.listen((MapLongPressEvent e) => _googleMapState.onLongPress(e.position)),
);
_streamSubscriptions.add(
GoogleMapsFlutterPlatform.instance
.onPointOfInterestTap(mapId: mapId)
.listen((PointOfInterestTapEvent e) => _googleMapState.onPointOfInterestTap(e.value)),
);
_streamSubscriptions.add(
GoogleMapsFlutterPlatform.instance
.onClusterTap(mapId: mapId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ class GoogleMap extends StatefulWidget {
this.onCameraIdle,
this.onTap,
this.onLongPress,
this.onPointOfInterestTap,
this.markerType = GoogleMapMarkerType.marker,
this.colorScheme,
String? mapId,
Expand Down Expand Up @@ -300,6 +301,14 @@ class GoogleMap extends StatefulWidget {
/// Called every time a [GoogleMap] is long pressed.
final ArgumentCallback<LatLng>? onLongPress;

/// Called when a point of interest on the map is tapped.
///
/// Supported on Android and web, and on iOS when using
/// `google_maps_flutter_ios_sdk9` or `google_maps_flutter_ios_sdk10`.
/// The default `google_maps_flutter_ios` package does not receive new
/// features, so this callback is not delivered there.
final ArgumentCallback<PointOfInterestId>? onPointOfInterestTap;

/// True if a "My Location" layer should be shown on the map.
///
/// This layer includes a location indicator at the current device location,
Expand Down Expand Up @@ -717,6 +726,13 @@ class _GoogleMapState extends State<GoogleMap> {
}
}

void onPointOfInterestTap(PointOfInterestId pointOfInterestId) {
final ArgumentCallback<PointOfInterestId>? onPointOfInterestTap = widget.onPointOfInterestTap;
if (onPointOfInterestTap != null) {
onPointOfInterestTap(pointOfInterestId);
}
}

void onClusterTap(Cluster cluster) {
final ClusterManager? clusterManager = _clusterManagers[cluster.clusterManagerId];
if (clusterManager == null) {
Expand Down
8 changes: 4 additions & 4 deletions packages/google_maps_flutter/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.
repository: https://github.com/flutter/packages/tree/main/packages/google_maps_flutter/google_maps_flutter
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+maps%22
version: 2.18.1
version: 2.19.0

environment:
sdk: ^3.11.0
Expand All @@ -21,10 +21,10 @@ flutter:
dependencies:
flutter:
sdk: flutter
google_maps_flutter_android: ^2.19.1
google_maps_flutter_android: ^2.20.0
google_maps_flutter_ios: ^2.18.0
google_maps_flutter_platform_interface: ^2.16.0
google_maps_flutter_web: ^0.6.3
google_maps_flutter_platform_interface: ^2.17.0
google_maps_flutter_web: ^0.6.4

dev_dependencies:
flutter_test:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,11 @@ class FakeGoogleMapsFlutterPlatform extends GoogleMapsFlutterPlatform {
return mapEventStreamController.stream.whereType<CircleTapEvent>();
}

@override
Stream<PointOfInterestTapEvent> onPointOfInterestTap({required int mapId}) {
return mapEventStreamController.stream.whereType<PointOfInterestTapEvent>();
}

@override
Stream<MapTapEvent> onTap({required int mapId}) {
return mapEventStreamController.stream.whereType<MapTapEvent>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ void main() {
main_file.MinMaxZoomPreference;
main_file.PatternItem;
main_file.PinConfig;
main_file.PointOfInterestId;
main_file.Polygon;
main_file.PolygonId;
main_file.Polyline;
Expand Down
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'));
});
}
Loading