Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.
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
Prev Previous commit
Next Next commit
manual fixes
  • Loading branch information
stuartmorgan-g committed May 20, 2022
commit fe0f0dc864c32c19576fe1af397b488d6b46f027
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class UnknownMapIDError extends Error {
class MethodChannelGoogleMapsFlutter extends GoogleMapsFlutterPlatform {
// Keep a collection of id -> channel
// Every method call passes the int mapId
final Map<int, MethodChannel> _channels = {};
final Map<int, MethodChannel> _channels = <int, MethodChannel>{};

/// Accesses the MethodChannel associated to the passed mapId.
MethodChannel channel(int mapId) {
Expand All @@ -61,7 +61,8 @@ class MethodChannelGoogleMapsFlutter extends GoogleMapsFlutterPlatform {
}

// Keep a collection of mapId to a map of TileOverlays.
final Map<int, Map<TileOverlayId, TileOverlay>> _tileOverlays = {};
final Map<int, Map<TileOverlayId, TileOverlay>> _tileOverlays =
<int, Map<TileOverlayId, TileOverlay>>{};

/// Returns the channel for [mapId], creating it if it doesn't already exist.
@visibleForTesting
Expand Down Expand Up @@ -92,12 +93,13 @@ class MethodChannelGoogleMapsFlutter extends GoogleMapsFlutterPlatform {
//
// It is a `broadcast` because multiple controllers will connect to
// different stream views of this Controller.
final StreamController<MapEvent> _mapEventStreamController =
StreamController<MapEvent>.broadcast();
final StreamController<MapEvent<Object?>> _mapEventStreamController =
StreamController<MapEvent<Object?>>.broadcast();

// Returns a filtered view of the events in the _controller, by mapId.
Stream<MapEvent> _events(int mapId) =>
_mapEventStreamController.stream.where((MapEvent event) => event.mapId == mapId);
Stream<MapEvent<Object?>> _events(int mapId) =>
_mapEventStreamController.stream
.where((MapEvent<Object?> event) => event.mapId == mapId);

@override
Stream<CameraMoveStartedEvent> onCameraMoveStarted({required int mapId}) {
Expand Down Expand Up @@ -181,52 +183,52 @@ class MethodChannelGoogleMapsFlutter extends GoogleMapsFlutterPlatform {
case 'marker#onTap':
_mapEventStreamController.add(MarkerTapEvent(
mapId,
MarkerId(call.arguments['markerId']),
MarkerId(call.arguments['markerId'] as String),
));
break;
case 'marker#onDragStart':
_mapEventStreamController.add(MarkerDragStartEvent(
mapId,
LatLng.fromJson(call.arguments['position'])!,
MarkerId(call.arguments['markerId']),
MarkerId(call.arguments['markerId'] as String),
));
break;
case 'marker#onDrag':
_mapEventStreamController.add(MarkerDragEvent(
mapId,
LatLng.fromJson(call.arguments['position'])!,
MarkerId(call.arguments['markerId']),
MarkerId(call.arguments['markerId'] as String),
));
break;
case 'marker#onDragEnd':
_mapEventStreamController.add(MarkerDragEndEvent(
mapId,
LatLng.fromJson(call.arguments['position'])!,
MarkerId(call.arguments['markerId']),
MarkerId(call.arguments['markerId'] as String),
));
break;
case 'infoWindow#onTap':
_mapEventStreamController.add(InfoWindowTapEvent(
mapId,
MarkerId(call.arguments['markerId']),
MarkerId(call.arguments['markerId'] as String),
));
break;
case 'polyline#onTap':
_mapEventStreamController.add(PolylineTapEvent(
mapId,
PolylineId(call.arguments['polylineId']),
PolylineId(call.arguments['polylineId'] as String),
));
break;
case 'polygon#onTap':
_mapEventStreamController.add(PolygonTapEvent(
mapId,
PolygonId(call.arguments['polygonId']),
PolygonId(call.arguments['polygonId'] as String),
));
break;
case 'circle#onTap':
_mapEventStreamController.add(CircleTapEvent(
mapId,
CircleId(call.arguments['circleId']),
CircleId(call.arguments['circleId'] as String),
));
break;
case 'map#onTap':
Expand All @@ -244,17 +246,17 @@ class MethodChannelGoogleMapsFlutter extends GoogleMapsFlutterPlatform {
case 'tileOverlay#getTile':
final Map<TileOverlayId, TileOverlay>? tileOverlaysForThisMap =
_tileOverlays[mapId];
final String tileOverlayId = call.arguments['tileOverlayId'];
final String tileOverlayId = call.arguments['tileOverlayId'] as String;
final TileOverlay? tileOverlay =
tileOverlaysForThisMap?[TileOverlayId(tileOverlayId)];
final TileProvider? tileProvider = tileOverlay?.tileProvider;
if (tileProvider == null) {
return TileProvider.noTile.toJson();
}
final Tile tile = await tileProvider.getTile(
call.arguments['x'],
call.arguments['y'],
call.arguments['zoom'],
call.arguments['x'] as int,
call.arguments['y'] as int,
call.arguments['zoom'] as int?,
);
return tile.toJson();
default:
Expand Down Expand Up @@ -381,9 +383,9 @@ class MethodChannelGoogleMapsFlutter extends GoogleMapsFlutterPlatform {
}) async {
final List<dynamic> successAndError = (await channel(mapId)
.invokeMethod<List<dynamic>>('map#setStyle', mapStyle))!;
final bool success = successAndError[0];
final bool success = successAndError[0] as bool;
if (!success) {
throw MapStyleException(successAndError[1]);
throw MapStyleException(successAndError[1] as String);
}
}

Expand Down Expand Up @@ -419,7 +421,7 @@ class MethodChannelGoogleMapsFlutter extends GoogleMapsFlutterPlatform {
final List<dynamic> latLng = (await channel(mapId)
.invokeMethod<List<dynamic>>(
'map#getLatLng', screenCoordinate.toJson()))!;
return LatLng(latLng[0], latLng[1]);
return LatLng(latLng[0] as double, latLng[1] as double);
}

@override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -358,8 +358,8 @@ abstract class GoogleMapsFlutterPlatform extends PlatformInterface {
Set<TileOverlay> tileOverlays = const <TileOverlay>{},
Set<Factory<OneSequenceGestureRecognizer>>? gestureRecognizers =
const <Factory<OneSequenceGestureRecognizer>>{},
// TODO: Replace with a structured type that's part of the interface.
// See https://github.com/flutter/flutter/issues/70330.
// TODO(stuartmorgan): Replace with a structured type that's part of the
// interface. See https://github.com/flutter/flutter/issues/70330.
Map<String, dynamic> mapOptions = const <String, dynamic>{},
}) {
throw UnimplementedError('buildView() has not been implemented.');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,25 @@ class BitmapDescriptor {
/// The inverse of .toJson.
// This is needed in Web to re-hydrate BitmapDescriptors that have been
// transformed to JSON for transport.
// TODO(https://github.com/flutter/flutter/issues/70330): Clean this up.
// TODO(stuartmorgan): Clean this up. See
// https://github.com/flutter/flutter/issues/70330
BitmapDescriptor.fromJson(Object json) : _json = json {
Copy link
Member

Choose a reason for hiding this comment

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

I had forgotten about this one 🤦

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think this one may actually be legacy after my first cleanup. After we do the rest of the cleanup we should mark things weren't not using ourselves now as deprecated.

assert(_json is List<dynamic>);
final List jsonList = json as List<dynamic>;
final List<dynamic> jsonList = json as List<dynamic>;
assert(_validTypes.contains(jsonList[0]));
switch (jsonList[0]) {
case _defaultMarker:
assert(jsonList.length <= 2);
if (jsonList.length == 2) {
assert(jsonList[1] is num);
assert(0 <= jsonList[1] && jsonList[1] < 360);
final num secondElement = jsonList[1] as num;
assert(0 <= secondElement && secondElement < 360);
}
break;
case _fromBytes:
assert(jsonList.length == 2);
assert(jsonList[1] != null && jsonList[1] is List<int>);
assert((jsonList[1] as List).isNotEmpty);
assert((jsonList[1] as List<int>).isNotEmpty);
break;
case _fromAsset:
assert(jsonList.length <= 3);
Expand All @@ -53,8 +55,8 @@ class BitmapDescriptor {
assert((jsonList[1] as String).isNotEmpty);
assert(jsonList[2] != null && jsonList[2] is double);
if (jsonList.length == 4) {
assert(jsonList[3] != null && jsonList[3] is List);
assert((jsonList[3] as List).length == 2);
assert(jsonList[3] != null && jsonList[3] is List<dynamic>);
assert((jsonList[3] as List<dynamic>).length == 2);
}
break;
default:
Expand All @@ -67,7 +69,7 @@ class BitmapDescriptor {
static const String _fromAssetImage = 'fromAssetImage';
static const String _fromBytes = 'fromBytes';

static const Set<String> _validTypes = {
static const Set<String> _validTypes = <String>{
_defaultMarker,
_fromAsset,
_fromAssetImage,
Expand Down Expand Up @@ -148,7 +150,7 @@ class BitmapDescriptor {
assetBundleImageKey.name,
assetBundleImageKey.scale,
if (kIsWeb && size != null)
[
<Object>[
size.width,
size.height,
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@

import 'dart:ui' show Offset;

import 'package:flutter/foundation.dart';

import 'types.dart';

/// The position of the map "camera", the view point from which the world is shown in the map view.
///
/// Aggregates the camera's [target] geographical location, its [zoom] level,
/// [tilt] angle, and [bearing].
@immutable
class CameraPosition {
/// Creates a immutable representation of the [GoogleMap] camera.
///
Expand Down Expand Up @@ -80,22 +83,26 @@ class CameraPosition {
return null;
}
return CameraPosition(
bearing: json['bearing'],
bearing: json['bearing'] as double,
target: target,
tilt: json['tilt'],
zoom: json['zoom'],
tilt: json['tilt'] as double,
zoom: json['zoom'] as double,
);
}

@override
bool operator ==(Object other) {
if (identical(this, other)) return true;
if (runtimeType != other.runtimeType) return false;
final CameraPosition typedOther = other as CameraPosition;
return bearing == typedOther.bearing &&
target == typedOther.target &&
tilt == typedOther.tilt &&
zoom == typedOther.zoom;
if (identical(this, other)) {
return true;
}
if (runtimeType != other.runtimeType) {
return false;
}
return other is CameraPosition &&
bearing == other.bearing &&
target == other.target &&
tilt == other.tilt &&
zoom == other.zoom;
}

@override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,18 +134,22 @@ class Circle implements MapsObject<Circle> {

@override
bool operator ==(Object other) {
if (identical(this, other)) return true;
if (other.runtimeType != runtimeType) return false;
final Circle typedOther = other as Circle;
return circleId == typedOther.circleId &&
consumeTapEvents == typedOther.consumeTapEvents &&
fillColor == typedOther.fillColor &&
center == typedOther.center &&
radius == typedOther.radius &&
strokeColor == typedOther.strokeColor &&
strokeWidth == typedOther.strokeWidth &&
visible == typedOther.visible &&
zIndex == typedOther.zIndex;
if (identical(this, other)) {
return true;
}
if (other.runtimeType != runtimeType) {
return false;
}
return other is Circle &&
circleId == other.circleId &&
consumeTapEvents == other.consumeTapEvents &&
fillColor == other.fillColor &&
center == other.center &&
radius == other.radius &&
strokeColor == other.strokeColor &&
strokeWidth == other.strokeWidth &&
visible == other.visible &&
zIndex == other.zIndex;
}

@override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:flutter/foundation.dart' show visibleForTesting;
import 'package:flutter/foundation.dart'
show immutable, objectRuntimeType, visibleForTesting;

/// A pair of latitude and longitude coordinates, stored as degrees.
@immutable
class LatLng {
/// Creates a geographical location specified in degrees [latitude] and
/// [longitude].
Expand Down Expand Up @@ -40,16 +42,19 @@ class LatLng {
return null;
}
assert(json is List && json.length == 2);
final List list = json as List;
return LatLng(list[0], list[1]);
final List<dynamic> list = json as List<dynamic>;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
final List<dynamic> list = json as List<dynamic>;
final List<Object?> list = json as List<Object?>;

No need to keep dynamic around?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, fixed. I think I just got burned enoughby careless removal of dynamic from plugin code early on that I'm still slightly nervous about it :)

return LatLng(list[0] as double, list[1] as double);
}

@override
String toString() => '$runtimeType($latitude, $longitude)';
String toString() =>
'${objectRuntimeType(this, 'LatLng')}($latitude, $longitude)';
Copy link
Member

Choose a reason for hiding this comment

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

Thanksssss!

This is going to make the example app look so much nicer on the Web!

Screen Shot 2022-05-20 at 2 56 21 PM


@override
bool operator ==(Object o) {
return o is LatLng && o.latitude == latitude && o.longitude == longitude;
bool operator ==(Object other) {
return other is LatLng &&
other.latitude == latitude &&
other.longitude == longitude;
}

@override
Expand All @@ -64,6 +69,7 @@ class LatLng {
/// if `southwest.longitude` ≤ `northeast.longitude`,
/// * lng ∈ [-180, `northeast.longitude`] ∪ [`southwest.longitude`, 180],
/// if `northeast.longitude` < `southwest.longitude`
@immutable
class LatLngBounds {
/// Creates geographical bounding box with the specified corners.
///
Expand Down Expand Up @@ -110,7 +116,7 @@ class LatLngBounds {
return null;
}
assert(json is List && json.length == 2);
final List list = json as List;
final List<dynamic> list = json as List<dynamic>;
return LatLngBounds(
southwest: LatLng.fromJson(list[0])!,
northeast: LatLng.fromJson(list[1])!,
Expand All @@ -119,14 +125,14 @@ class LatLngBounds {

@override
String toString() {
return '$runtimeType($southwest, $northeast)';
return '${objectRuntimeType(this, 'LatLngBounds')}($southwest, $northeast)';
}

@override
bool operator ==(Object o) {
return o is LatLngBounds &&
o.southwest == southwest &&
o.northeast == northeast;
bool operator ==(Object other) {
return other is LatLngBounds &&
other.southwest == southwest &&
other.northeast == northeast;
}

@override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,13 @@ class MapsObjectId<T> {

@override
bool operator ==(Object other) {
if (identical(this, other)) return true;
if (other.runtimeType != runtimeType) return false;
final MapsObjectId<T> typedOther = other as MapsObjectId<T>;
return value == typedOther.value;
if (identical(this, other)) {
return true;
}
if (other.runtimeType != runtimeType) {
return false;
}
return other is MapsObjectId<T> && value == other.value;
}

@override
Expand Down
Loading