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
More pre-migration adjustment
  • Loading branch information
stuartmorgan-g committed Feb 10, 2021
commit 0a703d7a5c31a3eede682b7bf2738384f626f39b
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,22 @@ import 'package:stream_transform/stream_transform.dart';
import '../types/tile_overlay_updates.dart';
import '../types/utils/tile_overlay.dart';

/// Error thrown when an unknown map ID is provided to a method channel API.
class UnknownMapIDError extends Error {
/// Message describing the assertion error.
final Object message;

/// Creates an assertion error with the provided [message].
UnknownMapIDError([this.message]);

String toString() {
if (message != null) {
return "Unknown map ID: ${Error.safeToString(message)}";
}
return "Unknown map ID";
}
}

/// An implementation of [GoogleMapsFlutterPlatform] that uses [MethodChannel] to communicate with the native code.
///
/// The `google_maps_flutter` plugin code itself never talks to the native code directly. It delegates
Expand All @@ -32,7 +48,11 @@ class MethodChannelGoogleMapsFlutter extends GoogleMapsFlutterPlatform {

/// Accesses the MethodChannel associated to the passed mapId.
MethodChannel channel(int mapId) {
return _channels[mapId];
MethodChannel channel = _channels[mapId];
if (channel == null) {
throw UnknownMapIDError();
Copy link
Member

Choose a reason for hiding this comment

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

Why not pass the mapId to the UnknownMapIDError() exception?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

An excellent question 🙂 Done!

}
return channel;
}

// Keep a collection of mapId to a map of TileOverlays.
Expand Down Expand Up @@ -190,16 +210,17 @@ class MethodChannelGoogleMapsFlutter extends GoogleMapsFlutterPlatform {
));
break;
case 'tileOverlay#getTile':
final Map<TileOverlayId, TileOverlay> tileOverlaysForThisMap =
final Map<TileOverlayId, TileOverlay>/*?*/ tileOverlaysForThisMap =
_tileOverlays[mapId];
final String tileOverlayId = call.arguments['tileOverlayId'];
/* XXX fix this*/
final TileOverlay tileOverlay =
tileOverlaysForThisMap[TileOverlayId(tileOverlayId)];
Tile tile;
Copy link
Contributor

Choose a reason for hiding this comment

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

nice catch! Thanks for the refactor!

if (tileOverlay == null || tileOverlay.tileProvider == null) {
tileOverlaysForThisMap/*?*/[TileOverlayId(tileOverlayId)];
TileProvider tileProvider = tileOverlay?.tileProvider;
if (tileProvider == null) {
return TileProvider.noTile.toJson();
}
tile = await tileOverlay.tileProvider.getTile(
final Tile tile = await tileProvider.getTile(
call.arguments['x'],
call.arguments['y'],
call.arguments['zoom'],
Expand Down Expand Up @@ -312,7 +333,7 @@ class MethodChannelGoogleMapsFlutter extends GoogleMapsFlutterPlatform {
/// If `newTileOverlays` is null, all the [TileOverlays] are removed for the Map with `mapId`.
@override
Future<void> updateTileOverlays({
Set<TileOverlay> newTileOverlays,
@required Set<TileOverlay> newTileOverlays,
@required int mapId,
}) {
final Map<TileOverlayId, TileOverlay> currentTileOverlays =
Expand Down Expand Up @@ -491,7 +512,7 @@ class MethodChannelGoogleMapsFlutter extends GoogleMapsFlutterPlatform {
/// * [showMarkerInfoWindow] to show the Info Window.
/// * [hideMarkerInfoWindow] to hide the Info Window.
@override
Future<bool> isMarkerInfoWindowShown(
Future<bool/*!*/> isMarkerInfoWindowShown(
MarkerId markerId, {
@required int mapId,
}) {
Expand All @@ -502,7 +523,7 @@ class MethodChannelGoogleMapsFlutter extends GoogleMapsFlutterPlatform {

/// Returns the current zoom level of the map
@override
Future<double> getZoomLevel({
Future<double/*!*/> getZoomLevel({
@required int mapId,
}) {
return channel(mapId).invokeMethod<double>('map#getZoomLevel');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ abstract class GoogleMapsFlutterPlatform extends PlatformInterface {
///
/// The returned [Future] completes after listeners have been notified.
Future<void> updateTileOverlays({
Set<TileOverlay> newTileOverlays,
@required Set<TileOverlay> newTileOverlays,
@required int mapId,
}) {
throw UnimplementedError('updateTileOverlays() has not been implemented.');
Expand Down Expand Up @@ -252,15 +252,15 @@ abstract class GoogleMapsFlutterPlatform extends PlatformInterface {
/// * See also:
/// * [showMarkerInfoWindow] to show the Info Window.
/// * [hideMarkerInfoWindow] to hide the Info Window.
Future<bool> isMarkerInfoWindowShown(
Future<bool/*!*/> isMarkerInfoWindowShown(
MarkerId markerId, {
@required int mapId,
}) {
throw UnimplementedError('updateMapOptions() has not been implemented.');
}

/// Returns the current zoom level of the map
Future<double> getZoomLevel({
Future<double/*!*/> getZoomLevel({
@required int mapId,
}) {
throw UnimplementedError('getZoomLevel() has not been implemented.');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ class CircleUpdates extends MapsObjectUpdates<Circle> {
CircleUpdates.from(Set<Circle> previous, Set<Circle> current) : super.from(previous, current, objectName: 'circle');

/// Set of Circles to be added in this update.
Set<Circle/*!*/> get circlesToAdd => objectsToAdd;
Set<Circle> get circlesToAdd => objectsToAdd;

/// Set of CircleIds to be removed in this update.
Set<CircleId>/*?*/ get circleIdsToRemove => objectIdsToRemove.cast<CircleId>();
Set<CircleId> get circleIdsToRemove => objectIdsToRemove.cast<CircleId>();

/// Set of Circles to be changed in this update.
Set<Circle/*!*/> get circlesToChange => objectsToChange;
Set<Circle> get circlesToChange => objectsToChange;
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class MapsObjectUpdates<T extends MapsObject> {
///
/// It is a programming error to call this with an ID that is not guaranteed
/// to be in [currentObjects].
T _idToCurrentObject(MapsObjectId<T> id) {
T/*!*/ _idToCurrentObject(MapsObjectId<T> id) {
return currentObjects[id];
}

Expand Down Expand Up @@ -73,21 +73,21 @@ class MapsObjectUpdates<T extends MapsObject> {
return _objectsToAdd;
}

Set<T> _objectsToAdd;
/*late*/ Set<T> _objectsToAdd;

/// Set of objects to be removed in this update.
Set<MapsObjectId<T>> get objectIdsToRemove {
return _objectIdsToRemove;
}

Set<MapsObjectId<T>> _objectIdsToRemove;
/*late*/ Set<MapsObjectId<T>> _objectIdsToRemove;

/// Set of objects to be changed in this update.
Set<T> get objectsToChange {
return _objectsToChange;
}

Set<T> _objectsToChange;
/*late*/ Set<T> _objectsToChange;

/// Converts this object to JSON.
Map<String, dynamic> toJson() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ class ScreenCoordinate {
});

/// Represents the number of pixels from the left of the [GoogleMap].
final int x;
final int/*!*/ x;

/// Represents the number of pixels from the top of the [GoogleMap].
final int y;
final int/*!*/ y;

/// Converts this object to something serializable in JSON.
dynamic toJson() {
return <String, int>{
return <String, int/*!*/>{
"x": x,
"y": y,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ class Tile {
const Tile(this.width, this.height, this.data);

/// The width of the image encoded by data in logical pixels.
final int width;
final int/*!*/ width;

/// The height of the image encoded by data in logical pixels.
final int height;
final int/*!*/ height;

/// A byte array containing the image data.
///
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ Map<CircleId, Circle> keyByCircleId(Iterable<Circle>/*?*/ circles) {
}

/// Converts a Set of Circles into something serializable in JSON.
List<Map<String, dynamic>> serializeCircleSet(Set<Circle/*!*/> circles) {
List<Map<String, dynamic>> serializeCircleSet(Set<Circle> circles) {
return serializeMapsObjectSet(circles);
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ Map<MarkerId, Marker> keyByMarkerId(Iterable<Marker>/*?*/ markers) {
}

/// Converts a Set of Markers into something serializable in JSON.
List<Map<String, dynamic>> serializeMarkerSet(Set<Marker/*!*/> markers) {
List<Map<String, dynamic>> serializeMarkerSet(Set<Marker> markers) {
return serializeMapsObjectSet(markers);
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ Map<PolygonId, Polygon> keyByPolygonId(Iterable<Polygon>/*?*/ polygons) {
}

/// Converts a Set of Polygons into something serializable in JSON.
List<Map<String, dynamic>> serializePolygonSet(Set<Polygon/*!*/> polygons) {
List<Map<String, dynamic>> serializePolygonSet(Set<Polygon> polygons) {
return serializeMapsObjectSet(polygons);
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import '../types.dart';
import 'maps_object.dart';

/// Converts an [Iterable] of TileOverlay in a Map of TileOverlayId -> TileOverlay.
Map<TileOverlayId/*!*/, TileOverlay> keyTileOverlayId(
Map<TileOverlayId, TileOverlay> keyTileOverlayId(
Iterable<TileOverlay>/*?*/ tileOverlays) {
return keyByMapsObjectId<TileOverlay>(tileOverlays).cast<TileOverlayId, TileOverlay>();
}

/// Converts a Set of TileOverlays into something serializable in JSON.
List<Map<String, dynamic>> serializeTileOverlaySet(
Set<TileOverlay/*!*/> tileOverlays) {
Set<TileOverlay> tileOverlays) {
return serializeMapsObjectSet(tileOverlays);
}