diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/CHANGELOG.md b/packages/google_maps_flutter/google_maps_flutter_platform_interface/CHANGELOG.md index d2e113d2f1a..44c04424e50 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/CHANGELOG.md +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/CHANGELOG.md @@ -1,5 +1,6 @@ -## NEXT +## 2.12.0 +* Deprecates `zIndex` parameter in `Marker` in favor of `zIndexInt`. * Updates minimum supported SDK version to Flutter 3.27/Dart 3.6. ## 2.11.1 diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/marker.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/marker.dart index 0921d2d4ec5..fa64d2d977c 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/marker.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/marker.dart @@ -135,7 +135,7 @@ class Marker implements MapsObject { /// * is positioned at 0, 0; [position] is `LatLng(0.0, 0.0)` /// * has an axis-aligned icon; [rotation] is 0.0 /// * is visible; [visible] is true - /// * is placed at the base of the drawing order; [zIndex] is 0.0 + /// * is placed at the base of the drawing order; [zIndexInt] is 0 /// * reports [onTap] events /// * reports [onDragEnd] events const Marker({ @@ -150,13 +150,21 @@ class Marker implements MapsObject { this.position = const LatLng(0.0, 0.0), this.rotation = 0.0, this.visible = true, - this.zIndex = 0.0, + @Deprecated( + 'Use zIndexInt instead. ' + 'On some platforms zIndex is truncated to an int, which can lead to incorrect/unstable ordering.', + ) + double zIndex = 0.0, + int zIndexInt = 0, this.clusterManagerId, this.onTap, this.onDrag, this.onDragStart, this.onDragEnd, - }) : assert(0.0 <= alpha && alpha <= 1.0); + }) : assert(0.0 <= alpha && alpha <= 1.0), + assert(zIndex == 0.0 || zIndexInt == 0, + 'Only one of zIndex and zIndexInt can be provided'), + _zIndexNum = zIndexInt == 0 ? zIndex : zIndexInt; /// Uniquely identifies a [Marker]. final MarkerId markerId; @@ -214,12 +222,26 @@ class Marker implements MapsObject { /// True if the marker is visible. final bool visible; + final num _zIndexNum; + + /// The z-index of the marker, used to determine relative drawing order of + /// map overlays. + /// + /// Overlays are drawn in order of z-index, so that lower values means drawn + /// earlier, and thus appearing to be closer to the surface of the Earth. + // TODO(stuartmorgan): Make this an int when removing the deprecated double zIndex parameter. + @Deprecated( + 'Use zIndexInt instead. ' + 'On some platforms zIndex is truncated to an int, which can lead to incorrect/unstable ordering.', + ) + double get zIndex => _zIndexNum.toDouble(); + /// The z-index of the marker, used to determine relative drawing order of /// map overlays. /// /// Overlays are drawn in order of z-index, so that lower values means drawn /// earlier, and thus appearing to be closer to the surface of the Earth. - final double zIndex; + int get zIndexInt => _zIndexNum.round(); /// Callbacks to receive tap events for markers placed on this map. final VoidCallback? onTap; @@ -246,7 +268,12 @@ class Marker implements MapsObject { LatLng? positionParam, double? rotationParam, bool? visibleParam, + @Deprecated( + 'Use zIndexIntParam instead. ' + 'On some platforms zIndex is truncated to an int, which can lead to incorrect/unstable ordering.', + ) double? zIndexParam, + int? zIndexIntParam, VoidCallback? onTapParam, ValueChanged? onDragStartParam, ValueChanged? onDragParam, @@ -266,6 +293,7 @@ class Marker implements MapsObject { rotation: rotationParam ?? rotation, visible: visibleParam ?? visible, zIndex: zIndexParam ?? zIndex, + zIndexInt: zIndexIntParam ?? zIndexInt, onTap: onTapParam ?? onTap, onDragStart: onDragStartParam ?? onDragStart, onDrag: onDragParam ?? onDrag, @@ -301,6 +329,7 @@ class Marker implements MapsObject { addIfPresent('rotation', rotation); addIfPresent('visible', visible); addIfPresent('zIndex', zIndex); + addIfPresent('zIndexInt', zIndexInt); addIfPresent('clusterManagerId', clusterManagerId?.value); return json; } @@ -326,6 +355,7 @@ class Marker implements MapsObject { rotation == other.rotation && visible == other.visible && zIndex == other.zIndex && + zIndexInt == other.zIndexInt && clusterManagerId == other.clusterManagerId; } diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/pubspec.yaml b/packages/google_maps_flutter/google_maps_flutter_platform_interface/pubspec.yaml index 27ce4594563..93df2f7f25e 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/pubspec.yaml +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/pubspec.yaml @@ -4,7 +4,7 @@ repository: https://github.com/flutter/packages/tree/main/packages/google_maps_f issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+maps%22 # NOTE: We strongly prefer non-breaking changes, even at the expense of a # less-clean API. See https://flutter.dev/go/platform-interface-breaking-changes -version: 2.11.1 +version: 2.12.0 environment: sdk: ^3.6.0 diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/test/types/marker_test.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/test/types/marker_test.dart index 76e5de2b186..35d16b4c7fa 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/test/types/marker_test.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/test/types/marker_test.dart @@ -3,7 +3,6 @@ // found in the LICENSE file. import 'package:flutter_test/flutter_test.dart'; - import 'package:google_maps_flutter_platform_interface/google_maps_flutter_platform_interface.dart'; void main() { @@ -24,6 +23,7 @@ void main() { expect(marker.rotation, equals(0.0)); expect(marker.visible, equals(true)); expect(marker.zIndex, equals(0.0)); + expect(marker.zIndexInt, equals(0)); expect(marker.onTap, equals(null)); expect(marker.onDrag, equals(null)); expect(marker.onDragStart, equals(null)); @@ -60,7 +60,7 @@ void main() { position: const LatLng(50, 50), rotation: 100, visible: false, - zIndex: 100, + zIndexInt: 100, onTap: () {}, onDragStart: (LatLng latLng) {}, onDrag: (LatLng latLng) {}, @@ -86,6 +86,7 @@ void main() { 'rotation': 100.0, 'visible': false, 'zIndex': 100.0, + 'zIndexInt': 100, }); }); test('clone', () { @@ -169,5 +170,36 @@ void main() { copy.onDragEnd!(const LatLng(0, 1)); expect(log, contains('onDragEndParam')); }); + + test("Assert that both zIndex and zIndex int aren't passed in", () { + expect( + () => Marker( + markerId: const MarkerId('ABC123'), + zIndex: 5, + zIndexInt: 10, + ), + throwsAssertionError, + ); + }); + + test('zIndex param', () { + const Marker marker = Marker( + markerId: MarkerId('ABC123'), + zIndex: 5.00, + ); + + expect(marker.zIndexInt, 5); + expect(marker.zIndex, 5.00); + }); + + test('zIndexInt param', () { + const Marker marker = Marker( + markerId: MarkerId('ABC123'), + zIndexInt: 5, + ); + + expect(marker.zIndexInt, 5); + expect(marker.zIndex, 5.00); + }); }); }