Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

Commit a71d033

Browse files
committed
Add drag event to platform interface
1 parent 1ac2978 commit a71d033

File tree

6 files changed

+71
-1
lines changed

6 files changed

+71
-1
lines changed

packages/google_maps_flutter/google_maps_flutter_platform_interface/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 1.0.5
2+
3+
* Add additional marker drag events
4+
15
## 1.0.4
26

37
* Add a `dispose` method to the interface, so implementations may cleanup resources acquired on `init`.

packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/events/map_event.dart

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,26 @@ class InfoWindowTapEvent extends MapEvent<MarkerId> {
102102
InfoWindowTapEvent(int mapId, MarkerId markerId) : super(mapId, markerId);
103103
}
104104

105+
/// An event fired when a [Marker] is starting to be dragged to a new [LatLng].
106+
class MarkerDragStartEvent extends _PositionedMapEvent<MarkerId> {
107+
/// Build a MarkerDragStar Event triggered from the map represented by `mapId`.
108+
///
109+
/// The `position` on this event is the [LatLng] on which the Marker was picked up from.
110+
/// The `value` of this event is a [MarkerId] object that represents the Marker.
111+
MarkerDragStartEvent(int mapId, LatLng position, MarkerId markerId)
112+
: super(mapId, position, markerId);
113+
}
114+
115+
/// An event fired when a [Marker] is being dragged to a new [LatLng].
116+
class MarkerDragEvent extends _PositionedMapEvent<MarkerId> {
117+
/// Build a MarkerDrag Event triggered from the map represented by `mapId`.
118+
///
119+
/// The `position` on this event is the [LatLng] on which the Marker was dragged to.
120+
/// The `value` of this event is a [MarkerId] object that represents the Marker.
121+
MarkerDragEvent(int mapId, LatLng position, MarkerId markerId)
122+
: super(mapId, position, markerId);
123+
}
124+
105125
/// An event fired when a [Marker] is dragged to a new [LatLng].
106126
class MarkerDragEndEvent extends _PositionedMapEvent<MarkerId> {
107127
/// Build a MarkerDragEnd Event triggered from the map represented by `mapId`.

packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/method_channel/method_channel_google_maps_flutter.dart

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,16 @@ class MethodChannelGoogleMapsFlutter extends GoogleMapsFlutterPlatform {
9191
return _events(mapId).whereType<InfoWindowTapEvent>();
9292
}
9393

94+
@override
95+
Stream<MarkerDragStartEvent> onMarkerDragStart({@required int mapId}) {
96+
return _events(mapId).whereType<MarkerDragStartEvent>();
97+
}
98+
99+
@override
100+
Stream<MarkerDragEvent> onMarkerDrag({@required int mapId}) {
101+
return _events(mapId).whereType<MarkerDragEvent>();
102+
}
103+
94104
@override
95105
Stream<MarkerDragEndEvent> onMarkerDragEnd({@required int mapId}) {
96106
return _events(mapId).whereType<MarkerDragEndEvent>();
@@ -141,6 +151,20 @@ class MethodChannelGoogleMapsFlutter extends GoogleMapsFlutterPlatform {
141151
MarkerId(call.arguments['markerId']),
142152
));
143153
break;
154+
case 'marker#onDragStart':
155+
_mapEventStreamController.add(MarkerDragStartEvent(
156+
mapId,
157+
LatLng.fromJson(call.arguments['position']),
158+
MarkerId(call.arguments['markerId']),
159+
));
160+
break;
161+
case 'marker#onDrag':
162+
_mapEventStreamController.add(MarkerDragEvent(
163+
mapId,
164+
LatLng.fromJson(call.arguments['position']),
165+
MarkerId(call.arguments['markerId']),
166+
));
167+
break;
144168
case 'marker#onDragEnd':
145169
_mapEventStreamController.add(MarkerDragEndEvent(
146170
mapId,

packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/platform_interface/google_maps_flutter_platform.dart

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,16 @@ abstract class GoogleMapsFlutterPlatform extends PlatformInterface {
274274
throw UnimplementedError('onInfoWindowTap() has not been implemented.');
275275
}
276276

277+
/// A [Marker] has been dragged to a different [LatLng] position.
278+
Stream<MarkerDragStartEvent> onMarkerDragStart({@required int mapId}) {
279+
throw UnimplementedError('onMarkerDragEnd() has not been implemented.');
280+
}
281+
282+
/// A [Marker] has been dragged to a different [LatLng] position.
283+
Stream<MarkerDragEvent> onMarkerDrag({@required int mapId}) {
284+
throw UnimplementedError('onMarkerDragEnd() has not been implemented.');
285+
}
286+
277287
/// A [Marker] has been dragged to a different [LatLng] position.
278288
Stream<MarkerDragEndEvent> onMarkerDragEnd({@required int mapId}) {
279289
throw UnimplementedError('onMarkerDragEnd() has not been implemented.');

packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/marker.dart

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,8 @@ class Marker {
169169
this.visible = true,
170170
this.zIndex = 0.0,
171171
this.onTap,
172+
this.onDrag,
173+
this.onDragStart,
172174
this.onDragEnd,
173175
}) : assert(alpha == null || (0.0 <= alpha && alpha <= 1.0));
174176

@@ -226,9 +228,15 @@ class Marker {
226228
/// Callbacks to receive tap events for markers placed on this map.
227229
final VoidCallback onTap;
228230

231+
/// Signature reporting the new [LatLng] at the start of a drag event.
232+
final ValueChanged<LatLng> onDragStart;
233+
229234
/// Signature reporting the new [LatLng] at the end of a drag event.
230235
final ValueChanged<LatLng> onDragEnd;
231236

237+
/// Signature reporting the new [LatLng] during the drag event.
238+
final ValueChanged<LatLng> onDrag;
239+
232240
/// Creates a new [Marker] object whose values are the same as this instance,
233241
/// unless overwritten by the specified parameters.
234242
Marker copyWith({
@@ -244,6 +252,8 @@ class Marker {
244252
bool visibleParam,
245253
double zIndexParam,
246254
VoidCallback onTapParam,
255+
ValueChanged<LatLng> onDragStartParam,
256+
ValueChanged<LatLng> onDragParam,
247257
ValueChanged<LatLng> onDragEndParam,
248258
}) {
249259
return Marker(
@@ -260,6 +270,8 @@ class Marker {
260270
visible: visibleParam ?? visible,
261271
zIndex: zIndexParam ?? zIndex,
262272
onTap: onTapParam ?? onTap,
273+
onDragStart: onDragStartParam ?? onDragStart,
274+
onDrag: onDragParam ?? onDrag,
263275
onDragEnd: onDragEndParam ?? onDragEnd,
264276
);
265277
}

packages/google_maps_flutter/google_maps_flutter_platform_interface/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ description: A common platform interface for the google_maps_flutter plugin.
33
homepage: https://github.com/flutter/plugins/tree/master/packages/google_maps_flutter/google_maps_flutter_platform_interface
44
# NOTE: We strongly prefer non-breaking changes, even at the expense of a
55
# less-clean API. See https://flutter.dev/go/platform-interface-breaking-changes
6-
version: 1.0.4
6+
version: 1.0.5
77

88
dependencies:
99
flutter:

0 commit comments

Comments
 (0)