Skip to content
Draft
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
4 changes: 4 additions & 0 deletions packages/google_maps_flutter/google_maps_flutter/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 2.18.0

* Adds support for editable polylines and polygons on web.

## 2.17.1

* Updates README to link to implementation packages for platform-specific
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,23 @@ class GoogleMapController {
.onPolylineTap(mapId: mapId)
.listen((PolylineTapEvent e) => _googleMapState.onPolylineTap(e.value)),
);
_streamSubscriptions.add(
GoogleMapsFlutterPlatform.instance
.onPolylineEdited(mapId: mapId)
.listen((PolylineEditEvent e) => _googleMapState.onPolylineEdited(e.value, e.points)),
);
_streamSubscriptions.add(
GoogleMapsFlutterPlatform.instance
.onPolygonTap(mapId: mapId)
.listen((PolygonTapEvent e) => _googleMapState.onPolygonTap(e.value)),
);
_streamSubscriptions.add(
GoogleMapsFlutterPlatform.instance
.onPolygonEdited(mapId: mapId)
.listen(
(PolygonEditEvent e) => _googleMapState.onPolygonEdited(e.value, e.points, e.holes),
),
);
_streamSubscriptions.add(
GoogleMapsFlutterPlatform.instance
.onCircleTap(mapId: mapId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,14 @@ class _GoogleMapState extends State<GoogleMap> {
}
}

void onPolygonEdited(PolygonId polygonId, List<LatLng> points, List<List<LatLng>> holes) {
final Polygon? polygon = _polygons[polygonId];
if (polygon == null) {
throw UnknownMapObjectIdError('polygon', polygonId, 'onEdited');
}
polygon.onEdited?.call(points, holes);
}

void onPolylineTap(PolylineId polylineId) {
final Polyline? polyline = _polylines[polylineId];
if (polyline == null) {
Expand All @@ -652,6 +660,14 @@ class _GoogleMapState extends State<GoogleMap> {
}
}

void onPolylineEdited(PolylineId polylineId, List<LatLng> points) {
final Polyline? polyline = _polylines[polylineId];
if (polyline == null) {
throw UnknownMapObjectIdError('polyline', polylineId, 'onEdited');
}
polyline.onEdited?.call(points);
}

void onCircleTap(CircleId circleId) {
final Circle? circle = _circles[circleId];
if (circle == null) {
Expand Down
6 changes: 3 additions & 3 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.17.1
version: 2.18.0

environment:
sdk: ^3.10.0
Expand All @@ -23,8 +23,8 @@ dependencies:
sdk: flutter
google_maps_flutter_android: ^2.19.1
google_maps_flutter_ios: ^2.18.0
google_maps_flutter_platform_interface: ^2.15.0
google_maps_flutter_web: ^0.6.2
google_maps_flutter_platform_interface: ^2.16.0
google_maps_flutter_web: ^0.7.0

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

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

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

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

@override
Stream<CircleTapEvent> onCircleTap({required int mapId}) {
return mapEventStreamController.stream.whereType<CircleTapEvent>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,37 @@ void main() {
expect(map.polygonUpdates.last.polygonsToAdd.isEmpty, true);
});

testWidgets('Setting editable triggers change', (WidgetTester tester) async {
const p1 = Polygon(polygonId: PolygonId('polygon_1'));
const p1Editable = Polygon(polygonId: PolygonId('polygon_1'), editable: true);

await tester.pumpWidget(_mapWithPolygons(<Polygon>{p1}));
await tester.pumpWidget(_mapWithPolygons(<Polygon>{p1Editable}));

final PlatformMapStateRecorder map = platform.lastCreatedMap;
expect(map.polygonUpdates.last.polygonsToChange.length, 1);
expect(map.polygonUpdates.last.polygonsToChange.first.editable, equals(true));
expect(map.polygonUpdates.last.polygonIdsToRemove.isEmpty, true);
expect(map.polygonUpdates.last.polygonsToAdd.isEmpty, true);
});

testWidgets('Update onEdited does not trigger platform change', (WidgetTester tester) async {
var p1 = const Polygon(polygonId: PolygonId('polygon_1'), editable: true);
await tester.pumpWidget(_mapWithPolygons(<Polygon>{p1}));

p1 = Polygon(
polygonId: const PolygonId('polygon_1'),
editable: true,
onEdited: (List<LatLng> points, List<List<LatLng>> holes) {},
);
await tester.pumpWidget(_mapWithPolygons(<Polygon>{p1}));

final PlatformMapStateRecorder map = platform.lastCreatedMap;
expect(map.polygonUpdates.last.polygonsToChange.isEmpty, true);
expect(map.polygonUpdates.last.polygonIdsToRemove.isEmpty, true);
expect(map.polygonUpdates.last.polygonsToAdd.isEmpty, true);
});

testWidgets('multi-update with delays', (WidgetTester tester) async {
platform.simulatePlatformDelay = true;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,37 @@ void main() {
expect(map.polylineUpdates.last.polylinesToAdd.isEmpty, true);
});

testWidgets('Setting editable triggers change', (WidgetTester tester) async {
const p1 = Polyline(polylineId: PolylineId('polyline_1'));
const p1Editable = Polyline(polylineId: PolylineId('polyline_1'), editable: true);

await tester.pumpWidget(_mapWithPolylines(<Polyline>{p1}));
await tester.pumpWidget(_mapWithPolylines(<Polyline>{p1Editable}));

final PlatformMapStateRecorder map = platform.lastCreatedMap;
expect(map.polylineUpdates.last.polylinesToChange.length, 1);
expect(map.polylineUpdates.last.polylinesToChange.first.editable, equals(true));
expect(map.polylineUpdates.last.polylineIdsToRemove.isEmpty, true);
expect(map.polylineUpdates.last.polylinesToAdd.isEmpty, true);
});

testWidgets('Update onEdited does not trigger platform change', (WidgetTester tester) async {
var p1 = const Polyline(polylineId: PolylineId('polyline_1'), editable: true);
await tester.pumpWidget(_mapWithPolylines(<Polyline>{p1}));

p1 = Polyline(
polylineId: const PolylineId('polyline_1'),
editable: true,
onEdited: (List<LatLng> points) {},
);
await tester.pumpWidget(_mapWithPolylines(<Polyline>{p1}));

final PlatformMapStateRecorder map = platform.lastCreatedMap;
expect(map.polylineUpdates.last.polylinesToChange.isEmpty, true);
expect(map.polylineUpdates.last.polylineIdsToRemove.isEmpty, true);
expect(map.polylineUpdates.last.polylinesToAdd.isEmpty, true);
});

testWidgets('multi-update with delays', (WidgetTester tester) async {
platform.simulatePlatformDelay = true;

Expand Down