Skip to content

[google_maps_flutter] Add a new zIndexInt param to marker and deprecate zIndex #8012

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 19 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
## NEXT
## 2.9.2

* Updates the example app to use the zIndexInt param instead of the deprecated zIndex.

## 2.9.1

* Updates README to indicate that Andoid SDK <21 is no longer supported.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -890,6 +890,7 @@ Marker _copyMarkerWithClusterManagerId(
rotation: marker.rotation,
visible: marker.visible,
zIndex: marker.zIndex,
zIndexInt: marker.zIndexInt,
onTap: marker.onTap,
onDragStart: marker.onDragStart,
onDrag: marker.onDrag,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,10 +249,10 @@ class PlaceMarkerBodyState extends State<PlaceMarkerBody> {

Future<void> _changeZIndex(MarkerId markerId) async {
final Marker marker = markers[markerId]!;
final double current = marker.zIndex;
final int current = marker.zIndexInt;
setState(() {
markers[markerId] = marker.copyWith(
zIndexParam: current == 12.0 ? 0.0 : current + 1.0,
zIndexIntParam: current == 12 ? 0 : current + 1,
);
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,8 @@ flutter:
uses-material-design: true
assets:
- assets/

# FOR TESTING AND INITIAL REVIEW ONLY. DO NOT MERGE.
# See https://github.com/flutter/flutter/blob/master/docs/ecosystem/contributing/README.md#changing-federated-plugins
dependency_overrides:
{google_maps_flutter_android: {path: ../../../../packages/google_maps_flutter/google_maps_flutter_android}, google_maps_flutter_ios: {path: ../../../../packages/google_maps_flutter/google_maps_flutter_ios}, google_maps_flutter_platform_interface: {path: ../../../../packages/google_maps_flutter/google_maps_flutter_platform_interface}}
18 changes: 17 additions & 1 deletion packages/google_maps_flutter/google_maps_flutter/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ version: 2.12.1

environment:
sdk: ^3.6.0
flutter: ">=3.27.0"
flutter: '>=3.27.0'

flutter:
plugin:
Expand Down Expand Up @@ -41,3 +41,19 @@ topics:
# The example deliberately includes limited-use secrets.
false_secrets:
- /example/web/index.html

# FOR TESTING AND INITIAL REVIEW ONLY. DO NOT MERGE.
# See https://github.com/flutter/flutter/blob/master/docs/ecosystem/contributing/README.md#changing-federated-plugins
dependency_overrides:
{
google_maps_flutter_android:
{
path: ../../../packages/google_maps_flutter/google_maps_flutter_android,
},
google_maps_flutter_ios:
{ path: ../../../packages/google_maps_flutter/google_maps_flutter_ios },
google_maps_flutter_platform_interface:
{
path: ../../../packages/google_maps_flutter/google_maps_flutter_platform_interface,
},
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 2.16.2

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

## 2.16.1

* Removes obsolete code related to supporting SDK <21.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2009,6 +2009,7 @@ Marker _copyMarkerWithClusterManagerId(
position: marker.position,
rotation: marker.rotation,
visible: marker.visible,
// The deprecated parameter is used here to avoid losing precision.
zIndex: marker.zIndex,
onTap: marker.onTap,
onDragStart: marker.onDragStart,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,8 @@ flutter:
uses-material-design: true
assets:
- assets/

# FOR TESTING AND INITIAL REVIEW ONLY. DO NOT MERGE.
# See https://github.com/flutter/flutter/blob/master/docs/ecosystem/contributing/README.md#changing-federated-plugins
dependency_overrides:
{google_maps_flutter_platform_interface: {path: ../../../../packages/google_maps_flutter/google_maps_flutter_platform_interface}}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ version: 2.16.1

environment:
sdk: ^3.6.0
flutter: ">=3.27.0"
flutter: '>=3.27.0'

flutter:
plugin:
Expand All @@ -30,10 +30,20 @@ dev_dependencies:
flutter_test:
sdk: flutter
mockito: ^5.4.4
pigeon: ^22.6.0
pigeon: ^22.7.4
plugin_platform_interface: ^2.1.7

topics:
- google-maps
- google-maps-flutter
- map

# FOR TESTING AND INITIAL REVIEW ONLY. DO NOT MERGE.
# See https://github.com/flutter/flutter/blob/master/docs/ecosystem/contributing/README.md#changing-federated-plugins
dependency_overrides:
{
google_maps_flutter_platform_interface:
{
path: ../../../packages/google_maps_flutter/google_maps_flutter_platform_interface,
},
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 2.15.3

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

## 2.15.2

* Fixes regression where updating a marker hides its info window.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,8 @@ flutter:
uses-material-design: true
assets:
- assets/

# FOR TESTING AND INITIAL REVIEW ONLY. DO NOT MERGE.
# See https://github.com/flutter/flutter/blob/master/docs/ecosystem/contributing/README.md#changing-federated-plugins
dependency_overrides:
{google_maps_flutter_platform_interface: {path: ../../../../../packages/google_maps_flutter/google_maps_flutter_platform_interface}}
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,8 @@ flutter:
uses-material-design: true
assets:
- assets/

# FOR TESTING AND INITIAL REVIEW ONLY. DO NOT MERGE.
# See https://github.com/flutter/flutter/blob/master/docs/ecosystem/contributing/README.md#changing-federated-plugins
dependency_overrides:
{google_maps_flutter_platform_interface: {path: ../../../../../packages/google_maps_flutter/google_maps_flutter_platform_interface}}
Original file line number Diff line number Diff line change
Expand Up @@ -269,10 +269,10 @@ class PlaceMarkerBodyState extends State<PlaceMarkerBody> {

Future<void> _changeZIndex(MarkerId markerId) async {
final Marker marker = markers[markerId]!;
final double current = marker.zIndex;
final int current = marker.zIndexInt;
setState(() {
markers[markerId] = marker.copyWith(
zIndexParam: current == 12.0 ? 0.0 : current + 1.0,
zIndexIntParam: current == 12 ? 0 : current + 1,
);
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,8 @@ dev_dependencies:

flutter:
uses-material-design: true

# FOR TESTING AND INITIAL REVIEW ONLY. DO NOT MERGE.
# See https://github.com/flutter/flutter/blob/master/docs/ecosystem/contributing/README.md#changing-federated-plugins
dependency_overrides:
{google_maps_flutter_platform_interface: {path: ../../../../../../packages/google_maps_flutter/google_maps_flutter_platform_interface}}
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ - (void)setVisible:(BOOL)visible {
}
}

- (void)setZIndex:(int)zIndex {
self.marker.zIndex = zIndex;
- (void)setZIndex:(int)zIndexInt {
self.marker.zIndexInt = zIndexInt;
}

- (void)updateFromPlatformMarker:(FGMPlatformMarker *)platformMarker
Expand All @@ -121,7 +121,7 @@ - (void)updateFromPlatformMarker:(FGMPlatformMarker *)platformMarker
[self setConsumeTapEvents:platformMarker.consumeTapEvents];
[self setPosition:FGMGetCoordinateForPigeonLatLng(platformMarker.position)];
[self setRotation:platformMarker.rotation];
[self setZIndex:platformMarker.zIndex];
[self setZIndexInt:platformMarker.zIndexInt];
FGMPlatformInfoWindow *infoWindow = platformMarker.infoWindow;
[self setInfoWindowAnchor:FGMGetCGPointForPigeonPoint(infoWindow.anchor)];
if (infoWindow.title) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ version: 2.15.2

environment:
sdk: ^3.4.0
flutter: ">=3.22.0"
flutter: '>=3.22.0'

flutter:
plugin:
Expand Down Expand Up @@ -35,3 +35,13 @@ topics:
- google-maps
- google-maps-flutter
- map

# FOR TESTING AND INITIAL REVIEW ONLY. DO NOT MERGE.
# See https://github.com/flutter/flutter/blob/master/docs/ecosystem/contributing/README.md#changing-federated-plugins
dependency_overrides:
{
google_maps_flutter_platform_interface:
{
path: ../../../packages/google_maps_flutter/google_maps_flutter_platform_interface,
},
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 2.12.0

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

## 2.11.1

* Updates READMEs and API docs.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ class Marker implements MapsObject<Marker> {
/// * 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({
Expand All @@ -150,13 +150,21 @@ class Marker implements MapsObject<Marker> {
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;
Expand Down Expand Up @@ -214,12 +222,26 @@ class Marker implements MapsObject<Marker> {
/// 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;
Expand All @@ -246,7 +268,12 @@ class Marker implements MapsObject<Marker> {
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<LatLng>? onDragStartParam,
ValueChanged<LatLng>? onDragParam,
Expand All @@ -266,6 +293,7 @@ class Marker implements MapsObject<Marker> {
rotation: rotationParam ?? rotation,
visible: visibleParam ?? visible,
zIndex: zIndexParam ?? zIndex,
zIndexInt: zIndexIntParam ?? zIndexInt,
onTap: onTapParam ?? onTap,
onDragStart: onDragStartParam ?? onDragStart,
onDrag: onDragParam ?? onDrag,
Expand Down Expand Up @@ -301,6 +329,7 @@ class Marker implements MapsObject<Marker> {
addIfPresent('rotation', rotation);
addIfPresent('visible', visible);
addIfPresent('zIndex', zIndex);
addIfPresent('zIndexInt', zIndexInt);
addIfPresent('clusterManagerId', clusterManagerId?.value);
return json;
}
Expand All @@ -326,6 +355,7 @@ class Marker implements MapsObject<Marker> {
rotation == other.rotation &&
visible == other.visible &&
zIndex == other.zIndex &&
zIndexInt == other.zIndexInt &&
clusterManagerId == other.clusterManagerId;
}

Expand All @@ -337,7 +367,7 @@ class Marker implements MapsObject<Marker> {
return 'Marker{markerId: $markerId, alpha: $alpha, anchor: $anchor, '
'consumeTapEvents: $consumeTapEvents, draggable: $draggable, flat: $flat, '
'icon: $icon, infoWindow: $infoWindow, position: $position, rotation: $rotation, '
'visible: $visible, zIndex: $zIndex, onTap: $onTap, onDragStart: $onDragStart, '
'visible: $visible, zIndex: $zIndex, zIndexInt:$zIndexInt onTap: $onTap, onDragStart: $onDragStart, '
'onDrag: $onDrag, onDragEnd: $onDragEnd, clusterManagerId: $clusterManagerId}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ version: 2.11.1

environment:
sdk: ^3.4.0
flutter: ">=3.22.0"
flutter: '>=3.22.0'

dependencies:
collection: ^1.15.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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));
Expand Down Expand Up @@ -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) {},
Expand All @@ -86,6 +86,7 @@ void main() {
'rotation': 100.0,
'visible': false,
'zIndex': 100.0,
'zIndexInt': 100,
});
});
test('clone', () {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.5.12 + 1

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

## 0.5.12

* Adds support for ground overlay.
Expand Down
Loading