Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
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,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
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 Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
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,
});
});
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per the comment on the main PR, this file needs tests that various combinations of passing zIndex and zIndexInt work as expected.

test('clone', () {
Expand Down Expand Up @@ -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);
});
});
}