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

[google_maps_flutter] Fix TileOverlay cloning #3771

Merged
merged 2 commits into from
Mar 30, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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,3 +1,8 @@
## 2.0.4

* Preserve the `TileProvider` when copying `TileOverlay`, fixing a
regression with tile overlays introduced in the null safety migration.

## 2.0.3

* Fix type issues in `isMarkerInfoWindowShown` and `getZoomLevel` introduced
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ class TileOverlay implements MapsObject {
/// unless overwritten by the specified parameters.
TileOverlay copyWith({
bool? fadeInParam,
TileProvider? tileProviderParam,
double? transparencyParam,
int? zIndexParam,
bool? visibleParam,
Expand All @@ -100,6 +101,7 @@ class TileOverlay implements MapsObject {
return TileOverlay(
tileOverlayId: tileOverlayId,
fadeIn: fadeInParam ?? fadeIn,
tileProvider: tileProviderParam ?? tileProvider,
transparency: transparencyParam ?? transparency,
zIndex: zIndexParam ?? zIndex,
visible: visibleParam ?? visible,
Expand Down Expand Up @@ -137,13 +139,14 @@ class TileOverlay implements MapsObject {
return other is TileOverlay &&
tileOverlayId == other.tileOverlayId &&
fadeIn == other.fadeIn &&
tileProvider == other.tileProvider &&
transparency == other.transparency &&
zIndex == other.zIndex &&
visible == other.visible &&
tileSize == other.tileSize;
}

@override
int get hashCode => hashValues(
tileOverlayId, fadeIn, transparency, zIndex, visible, tileSize);
int get hashCode => hashValues(tileOverlayId, fadeIn, tileProvider,
transparency, zIndex, visible, tileSize);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: A common platform interface for the google_maps_flutter plugin.
homepage: https://github.com/flutter/plugins/tree/master/packages/google_maps_flutter/google_maps_flutter_platform_interface
# 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.0.3
version: 2.0.4

dependencies:
flutter:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ import 'dart:ui' show hashValues;
import 'package:flutter_test/flutter_test.dart';
import 'package:google_maps_flutter_platform_interface/google_maps_flutter_platform_interface.dart';

class _TestTileProvider extends TileProvider {
@override
Future<Tile> getTile(int x, int y, int? zoom) async {
return Tile(0, 0, null);
}
}

void main() {
TestWidgetsFlutterBinding.ensureInitialized();

Expand Down Expand Up @@ -58,40 +65,65 @@ void main() {
});

test('equality', () async {
const TileOverlay tileOverlay1 = TileOverlay(
final TileProvider tileProvider = _TestTileProvider();
final TileOverlay tileOverlay1 = TileOverlay(
tileOverlayId: TileOverlayId('id1'),
fadeIn: false,
tileProvider: null,
tileProvider: tileProvider,
transparency: 0.1,
zIndex: 1,
visible: false,
tileSize: 128);
const TileOverlay tileOverlay2 = TileOverlay(
final TileOverlay tileOverlaySameValues = TileOverlay(
tileOverlayId: TileOverlayId('id1'),
fadeIn: false,
tileProvider: null,
tileProvider: tileProvider,
transparency: 0.1,
zIndex: 1,
visible: false,
tileSize: 128);
const TileOverlay tileOverlay3 = TileOverlay(
final TileOverlay tileOverlayDifferentId = TileOverlay(
tileOverlayId: TileOverlayId('id2'),
fadeIn: false,
tileProvider: tileProvider,
transparency: 0.1,
zIndex: 1,
visible: false,
tileSize: 128);
final TileOverlay tileOverlayDifferentProvider = TileOverlay(
tileOverlayId: TileOverlayId('id1'),
fadeIn: false,
tileProvider: null,
transparency: 0.1,
zIndex: 1,
visible: false,
tileSize: 128);
expect(tileOverlay1, tileOverlay2);
expect(tileOverlay1, isNot(tileOverlay3));
expect(tileOverlay1, tileOverlaySameValues);
expect(tileOverlay1, isNot(tileOverlayDifferentId));
expect(tileOverlay1, isNot(tileOverlayDifferentProvider));
});

test('clone', () async {
final TileProvider tileProvider = _TestTileProvider();
// Set non-default values for every parameter.
final TileOverlay tileOverlay = TileOverlay(
tileOverlayId: TileOverlayId('id1'),
fadeIn: false,
tileProvider: tileProvider,
transparency: 0.1,
zIndex: 1,
visible: false,
tileSize: 128);
expect(tileOverlay, tileOverlay.clone());
});

test('hashCode', () async {
final TileProvider tileProvider = _TestTileProvider();
const TileOverlayId id = TileOverlayId('id1');
const TileOverlay tileOverlay = TileOverlay(
final TileOverlay tileOverlay = TileOverlay(
tileOverlayId: id,
fadeIn: false,
tileProvider: null,
tileProvider: tileProvider,
transparency: 0.1,
zIndex: 1,
visible: false,
Expand All @@ -101,6 +133,7 @@ void main() {
hashValues(
tileOverlay.tileOverlayId,
tileOverlay.fadeIn,
tileOverlay.tileProvider,
tileOverlay.transparency,
tileOverlay.zIndex,
tileOverlay.visible,
Expand Down