[google_maps_flutter_web] Add Marker drag events (#4385)
diff --git a/packages/google_maps_flutter/google_maps_flutter_web/CHANGELOG.md b/packages/google_maps_flutter/google_maps_flutter_web/CHANGELOG.md
index 4d7ecf7..b2fe086 100644
--- a/packages/google_maps_flutter/google_maps_flutter_web/CHANGELOG.md
+++ b/packages/google_maps_flutter/google_maps_flutter_web/CHANGELOG.md
@@ -1,3 +1,7 @@
+## 0.3.2
+
+Add `onDragStart` and `onDrag` to `Marker`
+
## 0.3.1
* Fix the `getScreenCoordinate(LatLng)` method. [#80710](https://github.com/flutter/flutter/issues/80710)
diff --git a/packages/google_maps_flutter/google_maps_flutter_web/example/integration_test/google_maps_controller_test.mocks.dart b/packages/google_maps_flutter/google_maps_flutter_web/example/integration_test/google_maps_controller_test.mocks.dart
index af8ed54..530707c 100644
--- a/packages/google_maps_flutter/google_maps_flutter_web/example/integration_test/google_maps_controller_test.mocks.dart
+++ b/packages/google_maps_flutter/google_maps_flutter_web/example/integration_test/google_maps_controller_test.mocks.dart
@@ -1,8 +1,4 @@
-// Copyright 2013 The Flutter Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Mocks generated by Mockito 5.0.15 from annotations
+// Mocks generated by Mockito 5.0.16 from annotations
// in google_maps_flutter_web_integration_tests/integration_test/google_maps_controller_test.dart.
// Do not manually edit this file.
@@ -19,6 +15,7 @@
// ignore_for_file: invalid_use_of_visible_for_testing_member
// ignore_for_file: prefer_const_constructors
// ignore_for_file: unnecessary_parenthesis
+// ignore_for_file: camel_case_types
class _FakeGMap_0 extends _i1.Fake implements _i2.GMap {}
diff --git a/packages/google_maps_flutter/google_maps_flutter_web/example/integration_test/google_maps_plugin_test.dart b/packages/google_maps_flutter/google_maps_flutter_web/example/integration_test/google_maps_plugin_test.dart
index 758294f..a3cf86e 100644
--- a/packages/google_maps_flutter/google_maps_flutter_web/example/integration_test/google_maps_plugin_test.dart
+++ b/packages/google_maps_flutter/google_maps_flutter_web/example/integration_test/google_maps_plugin_test.dart
@@ -404,6 +404,28 @@
await _testStreamFiltering(stream, event);
});
+ testWidgets('onMarkerDragStart', (WidgetTester tester) async {
+ final event = MarkerDragStartEvent(
+ mapId,
+ LatLng(43.3677, -5.8372),
+ MarkerId('test-123'),
+ );
+
+ final stream = plugin.onMarkerDragStart(mapId: mapId);
+
+ await _testStreamFiltering(stream, event);
+ });
+ testWidgets('onMarkerDrag', (WidgetTester tester) async {
+ final event = MarkerDragEvent(
+ mapId,
+ LatLng(43.3677, -5.8372),
+ MarkerId('test-123'),
+ );
+
+ final stream = plugin.onMarkerDrag(mapId: mapId);
+
+ await _testStreamFiltering(stream, event);
+ });
testWidgets('onMarkerDragEnd', (WidgetTester tester) async {
final event = MarkerDragEndEvent(
mapId,
diff --git a/packages/google_maps_flutter/google_maps_flutter_web/example/integration_test/google_maps_plugin_test.mocks.dart b/packages/google_maps_flutter/google_maps_flutter_web/example/integration_test/google_maps_plugin_test.mocks.dart
index 01908ce..d2df11c 100644
--- a/packages/google_maps_flutter/google_maps_flutter_web/example/integration_test/google_maps_plugin_test.mocks.dart
+++ b/packages/google_maps_flutter/google_maps_flutter_web/example/integration_test/google_maps_plugin_test.mocks.dart
@@ -1,8 +1,4 @@
-// Copyright 2013 The Flutter Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Mocks generated by Mockito 5.0.15 from annotations
+// Mocks generated by Mockito 5.0.16 from annotations
// in google_maps_flutter_web_integration_tests/integration_test/google_maps_plugin_test.dart.
// Do not manually edit this file.
@@ -20,6 +16,7 @@
// ignore_for_file: invalid_use_of_visible_for_testing_member
// ignore_for_file: prefer_const_constructors
// ignore_for_file: unnecessary_parenthesis
+// ignore_for_file: camel_case_types
class _FakeStreamController_0<T> extends _i1.Fake
implements _i2.StreamController<T> {}
diff --git a/packages/google_maps_flutter/google_maps_flutter_web/example/integration_test/marker_test.dart b/packages/google_maps_flutter/google_maps_flutter_web/example/integration_test/marker_test.dart
index 2bfa27b..cfa36fe 100644
--- a/packages/google_maps_flutter/google_maps_flutter_web/example/integration_test/marker_test.dart
+++ b/packages/google_maps_flutter/google_maps_flutter_web/example/integration_test/marker_test.dart
@@ -27,6 +27,14 @@
_methodCalledCompleter.complete(true);
}
+ void onDragStart(gmaps.LatLng _) {
+ _methodCalledCompleter.complete(true);
+ }
+
+ void onDrag(gmaps.LatLng _) {
+ _methodCalledCompleter.complete(true);
+ }
+
void onDragEnd(gmaps.LatLng _) {
_methodCalledCompleter.complete(true);
}
@@ -53,6 +61,26 @@
expect(await methodCalled, isTrue);
});
+ testWidgets('onDragStart gets called', (WidgetTester tester) async {
+ MarkerController(marker: marker, onDragStart: onDragStart);
+
+ // Trigger a drag end event...
+ gmaps.Event.trigger(marker, 'dragstart',
+ [gmaps.MapMouseEvent()..latLng = gmaps.LatLng(0, 0)]);
+
+ expect(await methodCalled, isTrue);
+ });
+
+ testWidgets('onDrag gets called', (WidgetTester tester) async {
+ MarkerController(marker: marker, onDrag: onDrag);
+
+ // Trigger a drag end event...
+ gmaps.Event.trigger(
+ marker, 'drag', [gmaps.MapMouseEvent()..latLng = gmaps.LatLng(0, 0)]);
+
+ expect(await methodCalled, isTrue);
+ });
+
testWidgets('onDragEnd gets called', (WidgetTester tester) async {
MarkerController(marker: marker, onDragEnd: onDragEnd);
diff --git a/packages/google_maps_flutter/google_maps_flutter_web/example/pubspec.yaml b/packages/google_maps_flutter/google_maps_flutter_web/example/pubspec.yaml
index 249b893..95a3d42 100644
--- a/packages/google_maps_flutter/google_maps_flutter_web/example/pubspec.yaml
+++ b/packages/google_maps_flutter/google_maps_flutter_web/example/pubspec.yaml
@@ -4,7 +4,7 @@
# Tests require flutter beta or greater to run.
environment:
sdk: ">=2.12.0 <3.0.0"
- flutter: ">=2.1.0"
+ flutter: ">=2.1.0"
dependencies:
google_maps_flutter_web:
diff --git a/packages/google_maps_flutter/google_maps_flutter_web/lib/src/google_maps_flutter_web.dart b/packages/google_maps_flutter/google_maps_flutter_web/lib/src/google_maps_flutter_web.dart
index d03dec9..47bfdc7 100644
--- a/packages/google_maps_flutter/google_maps_flutter_web/lib/src/google_maps_flutter_web.dart
+++ b/packages/google_maps_flutter/google_maps_flutter_web/lib/src/google_maps_flutter_web.dart
@@ -241,6 +241,16 @@
}
@override
+ Stream<MarkerDragStartEvent> onMarkerDragStart({required int mapId}) {
+ return _events(mapId).whereType<MarkerDragStartEvent>();
+ }
+
+ @override
+ Stream<MarkerDragEvent> onMarkerDrag({required int mapId}) {
+ return _events(mapId).whereType<MarkerDragEvent>();
+ }
+
+ @override
Stream<MarkerDragEndEvent> onMarkerDragEnd({required int mapId}) {
return _events(mapId).whereType<MarkerDragEndEvent>();
}
diff --git a/packages/google_maps_flutter/google_maps_flutter_web/lib/src/marker.dart b/packages/google_maps_flutter/google_maps_flutter_web/lib/src/marker.dart
index 5b0169b..c4cd40f 100644
--- a/packages/google_maps_flutter/google_maps_flutter_web/lib/src/marker.dart
+++ b/packages/google_maps_flutter/google_maps_flutter_web/lib/src/marker.dart
@@ -19,6 +19,8 @@
required gmaps.Marker marker,
gmaps.InfoWindow? infoWindow,
bool consumeTapEvents = false,
+ LatLngCallback? onDragStart,
+ LatLngCallback? onDrag,
LatLngCallback? onDragEnd,
ui.VoidCallback? onTap,
}) : _marker = marker,
@@ -29,6 +31,22 @@
onTap.call();
});
}
+ if (onDragStart != null) {
+ marker.onDragstart.listen((event) {
+ if (marker != null) {
+ marker.position = event.latLng;
+ }
+ onDragStart.call(event.latLng ?? _nullGmapsLatLng);
+ });
+ }
+ if (onDrag != null) {
+ marker.onDrag.listen((event) {
+ if (marker != null) {
+ marker.position = event.latLng;
+ }
+ onDrag.call(event.latLng ?? _nullGmapsLatLng);
+ });
+ }
if (onDragEnd != null) {
marker.onDragend.listen((event) {
if (marker != null) {
diff --git a/packages/google_maps_flutter/google_maps_flutter_web/lib/src/markers.dart b/packages/google_maps_flutter/google_maps_flutter_web/lib/src/markers.dart
index b650b9b..542a48b 100644
--- a/packages/google_maps_flutter/google_maps_flutter_web/lib/src/markers.dart
+++ b/packages/google_maps_flutter/google_maps_flutter_web/lib/src/markers.dart
@@ -62,6 +62,12 @@
this.showMarkerInfoWindow(marker.markerId);
_onMarkerTap(marker.markerId);
},
+ onDragStart: (gmaps.LatLng latLng) {
+ _onMarkerDragStart(marker.markerId, latLng);
+ },
+ onDrag: (gmaps.LatLng latLng) {
+ _onMarkerDrag(marker.markerId, latLng);
+ },
onDragEnd: (gmaps.LatLng latLng) {
_onMarkerDragEnd(marker.markerId, latLng);
},
@@ -140,6 +146,22 @@
_streamController.add(InfoWindowTapEvent(mapId, markerId));
}
+ void _onMarkerDragStart(MarkerId markerId, gmaps.LatLng latLng) {
+ _streamController.add(MarkerDragStartEvent(
+ mapId,
+ _gmLatLngToLatLng(latLng),
+ markerId,
+ ));
+ }
+
+ void _onMarkerDrag(MarkerId markerId, gmaps.LatLng latLng) {
+ _streamController.add(MarkerDragEvent(
+ mapId,
+ _gmLatLngToLatLng(latLng),
+ markerId,
+ ));
+ }
+
void _onMarkerDragEnd(MarkerId markerId, gmaps.LatLng latLng) {
_streamController.add(MarkerDragEndEvent(
mapId,
diff --git a/packages/google_maps_flutter/google_maps_flutter_web/pubspec.yaml b/packages/google_maps_flutter/google_maps_flutter_web/pubspec.yaml
index 08eda25..1f5fe4d 100644
--- a/packages/google_maps_flutter/google_maps_flutter_web/pubspec.yaml
+++ b/packages/google_maps_flutter/google_maps_flutter_web/pubspec.yaml
@@ -2,7 +2,7 @@
description: Web platform implementation of google_maps_flutter
repository: https://github.com/flutter/plugins/tree/master/packages/google_maps_flutter/google_maps_flutter_web
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+maps%22
-version: 0.3.1
+version: 0.3.2
environment:
sdk: ">=2.12.0 <3.0.0"
@@ -21,7 +21,7 @@
sdk: flutter
flutter_web_plugins:
sdk: flutter
- google_maps_flutter_platform_interface: ^2.0.1
+ google_maps_flutter_platform_interface: ^2.1.2
google_maps: ^5.2.0
meta: ^1.3.0
sanitize_html: ^2.0.0