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

Commit 03c3c54

Browse files
committed
[google_maps_flutter_web] Allow marker position updates
Unconditionally convert the current marker position in `convert.dart:_markerOptionsFromMarker`, to allow for position updates. Also adds position changes to `marker_test.dart/MarkerController/update` and `markers_test.dart/MarkersController/changeMarkers`. The `MarkersController` case is fixed by this patch.
1 parent 923f757 commit 03c3c54

File tree

5 files changed

+22
-13
lines changed

5 files changed

+22
-13
lines changed

packages/google_maps_flutter/google_maps_flutter_web/CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
## NEXT
1+
## 0.4.0+4
22

3+
* Allows marker position updates. Issue [#83467](https://github.com/flutter/flutter/issues/83467).
34
* Updates code for `no_leading_underscores_for_local_identifiers` lint.
45

56
## 0.4.0+3

packages/google_maps_flutter/google_maps_flutter_web/example/integration_test/marker_test.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,16 @@ void main() {
100100
testWidgets('update', (WidgetTester tester) async {
101101
final MarkerController controller = MarkerController(marker: marker);
102102
final gmaps.MarkerOptions options = gmaps.MarkerOptions()
103-
..draggable = true;
103+
..draggable = true
104+
..position = gmaps.LatLng(42, 54);
104105

105106
expect(marker.draggable, isNull);
106107

107108
controller.update(options);
108109

109110
expect(marker.draggable, isTrue);
111+
expect(marker.position?.lat, equals(42));
112+
expect(marker.position?.lng, equals(54));
110113
});
111114

112115
testWidgets('infoWindow null, showInfoWindow.',

packages/google_maps_flutter/google_maps_flutter_web/example/integration_test/markers_test.dart

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,22 @@ void main() {
5555
expect(
5656
controller.markers[const MarkerId('1')]?.marker?.draggable, isFalse);
5757

58-
// Update the marker with radius 10
58+
// Update the marker with draggability and position
5959
final Set<Marker> updatedMarkers = <Marker>{
60-
const Marker(markerId: MarkerId('1'), draggable: true),
60+
const Marker(
61+
markerId: MarkerId('1'),
62+
draggable: true,
63+
position: LatLng(42, 54),
64+
),
6165
};
6266
controller.changeMarkers(updatedMarkers);
6367

6468
expect(controller.markers.length, 1);
65-
expect(
66-
controller.markers[const MarkerId('1')]?.marker?.draggable, isTrue);
69+
final gmaps.Marker? marker =
70+
controller.markers[const MarkerId('1')]?.marker;
71+
expect(marker?.draggable, isTrue);
72+
expect(marker?.position?.lat, equals(42));
73+
expect(marker?.position?.lng, equals(54));
6774
});
6875

6976
testWidgets('removeMarkers', (WidgetTester tester) async {

packages/google_maps_flutter/google_maps_flutter_web/lib/src/convert.dart

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -284,17 +284,15 @@ gmaps.Icon? _gmIconFromBitmapDescriptor(BitmapDescriptor bitmapDescriptor) {
284284

285285
// Computes the options for a new [gmaps.Marker] from an incoming set of options
286286
// [marker], and the existing marker registered with the map: [currentMarker].
287-
// Preserves the position from the [currentMarker], if set.
288287
gmaps.MarkerOptions _markerOptionsFromMarker(
289288
Marker marker,
290289
gmaps.Marker? currentMarker,
291290
) {
292291
return gmaps.MarkerOptions()
293-
..position = currentMarker?.position ??
294-
gmaps.LatLng(
295-
marker.position.latitude,
296-
marker.position.longitude,
297-
)
292+
..position = gmaps.LatLng(
293+
marker.position.latitude,
294+
marker.position.longitude,
295+
)
298296
..title = sanitizeHtml(marker.infoWindow.title ?? '')
299297
..zIndex = marker.zIndex
300298
..visible = marker.visible

packages/google_maps_flutter/google_maps_flutter_web/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: google_maps_flutter_web
22
description: Web platform implementation of google_maps_flutter
33
repository: https://github.com/flutter/plugins/tree/main/packages/google_maps_flutter/google_maps_flutter_web
44
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+maps%22
5-
version: 0.4.0+3
5+
version: 0.4.0+4
66

77
environment:
88
sdk: ">=2.12.0 <3.0.0"

0 commit comments

Comments
 (0)