Skip to content

Commit 1e7fcd2

Browse files
authored
Fix the zIndex-related issue in the copyWith method. (#9396)
This assertion fails when using the `copyWith` method. https://github.com/flutter/packages/blob/007e2f1e468b8e870544c16ce21ad39f97299241/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/marker.dart#L165 ## Pre-Review Checklist [^1]: Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling.
1 parent c05fd0b commit 1e7fcd2

File tree

4 files changed

+28
-3
lines changed

4 files changed

+28
-3
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+
## 2.12.1
2+
3+
* Fixes the `zIndex` issue in the `copyWith` method.
4+
15
## 2.12.0
26

37
* Deprecates `zIndex` parameter in `Marker` in favor of `zIndexInt`.

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,8 @@ class Marker implements MapsObject<Marker> {
280280
ValueChanged<LatLng>? onDragEndParam,
281281
ClusterManagerId? clusterManagerIdParam,
282282
}) {
283+
assert(zIndexParam == null || zIndexIntParam == null,
284+
'Only one of zIndexParam and zIndexIntParam can be provided');
283285
return Marker(
284286
markerId: markerId,
285287
alpha: alphaParam ?? alpha,
@@ -292,8 +294,7 @@ class Marker implements MapsObject<Marker> {
292294
position: positionParam ?? position,
293295
rotation: rotationParam ?? rotation,
294296
visible: visibleParam ?? visible,
295-
zIndex: zIndexParam ?? zIndex,
296-
zIndexInt: zIndexIntParam ?? zIndexInt,
297+
zIndex: zIndexIntParam?.toDouble() ?? zIndexParam ?? zIndex,
297298
onTap: onTapParam ?? onTap,
298299
onDragStart: onDragStartParam ?? onDragStart,
299300
onDrag: onDragParam ?? onDrag,

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
@@ -4,7 +4,7 @@ repository: https://github.com/flutter/packages/tree/main/packages/google_maps_f
44
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+maps%22
55
# NOTE: We strongly prefer non-breaking changes, even at the expense of a
66
# less-clean API. See https://flutter.dev/go/platform-interface-breaking-changes
7-
version: 2.12.0
7+
version: 2.12.1
88

99
environment:
1010
sdk: ^3.6.0

packages/google_maps_flutter/google_maps_flutter_platform_interface/test/types/marker_test.dart

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,5 +201,25 @@ void main() {
201201
expect(marker.zIndexInt, 5);
202202
expect(marker.zIndex, 5.00);
203203
});
204+
205+
test('zIndexInt param copyWith', () {
206+
const Marker marker = Marker(
207+
markerId: MarkerId('ABC123'),
208+
zIndexInt: 5,
209+
);
210+
final Marker copy = marker.copyWith(zIndexIntParam: 10);
211+
expect(copy.zIndexInt, 10);
212+
expect(copy.zIndex, 10.0);
213+
});
214+
215+
test('zIndex param copyWith', () {
216+
const Marker marker = Marker(
217+
markerId: MarkerId('ABC123'),
218+
zIndexInt: 5,
219+
);
220+
final Marker copy = marker.copyWith(zIndexParam: 10.0);
221+
expect(copy.zIndexInt, 10);
222+
expect(copy.zIndex, 10.0);
223+
});
204224
});
205225
}

0 commit comments

Comments
 (0)