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
Show all changes
23 commits
Select commit Hold shift + click to select a range
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
Replace Mockito and get the tests passing
  • Loading branch information
stuartmorgan-g committed Feb 15, 2021
commit 675c88ff0f53ed526858001c72698bad572bbd13
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@

part of google_maps_flutter;

final GoogleMapsFlutterPlatform _googleMapsFlutterPlatform =
GoogleMapsFlutterPlatform.instance;

/// Controller for a single GoogleMap instance running on the host platform.
class GoogleMapController {
/// The mapId for this controller
Expand All @@ -16,7 +13,7 @@ class GoogleMapController {
CameraPosition initialCameraPosition,
this._googleMapState, {
required this.mapId,
}) : assert(_googleMapsFlutterPlatform != null) {
}) : assert(GoogleMapsFlutterPlatform.instance != null) {
_connectStreams(mapId);
}

Expand All @@ -30,7 +27,7 @@ class GoogleMapController {
_GoogleMapState googleMapState,
) async {
assert(id != null);
await _googleMapsFlutterPlatform.init(id);
await GoogleMapsFlutterPlatform.instance.init(id);
return GoogleMapController._(
initialCameraPosition,
googleMapState,
Expand All @@ -44,8 +41,8 @@ class GoogleMapController {
// TODO(dit) https://github.com/flutter/flutter/issues/55504 Remove this getter.
@visibleForTesting
MethodChannel? get channel {
if (_googleMapsFlutterPlatform is MethodChannelGoogleMapsFlutter) {
return (_googleMapsFlutterPlatform as MethodChannelGoogleMapsFlutter)
if (GoogleMapsFlutterPlatform.instance is MethodChannelGoogleMapsFlutter) {
return (GoogleMapsFlutterPlatform.instance as MethodChannelGoogleMapsFlutter)
.channel(mapId);
}
return null;
Expand All @@ -55,40 +52,40 @@ class GoogleMapController {

void _connectStreams(int mapId) {
if (_googleMapState.widget.onCameraMoveStarted != null) {
_googleMapsFlutterPlatform
GoogleMapsFlutterPlatform.instance
.onCameraMoveStarted(mapId: mapId)
.listen((_) => _googleMapState.widget.onCameraMoveStarted!());
}
if (_googleMapState.widget.onCameraMove != null) {
_googleMapsFlutterPlatform.onCameraMove(mapId: mapId).listen(
GoogleMapsFlutterPlatform.instance.onCameraMove(mapId: mapId).listen(
(CameraMoveEvent e) => _googleMapState.widget.onCameraMove!(e.value));
}
if (_googleMapState.widget.onCameraIdle != null) {
_googleMapsFlutterPlatform
GoogleMapsFlutterPlatform.instance
.onCameraIdle(mapId: mapId)
.listen((_) => _googleMapState.widget.onCameraIdle!());
}
_googleMapsFlutterPlatform
GoogleMapsFlutterPlatform.instance
.onMarkerTap(mapId: mapId)
.listen((MarkerTapEvent e) => _googleMapState.onMarkerTap(e.value));
_googleMapsFlutterPlatform.onMarkerDragEnd(mapId: mapId).listen(
GoogleMapsFlutterPlatform.instance.onMarkerDragEnd(mapId: mapId).listen(
(MarkerDragEndEvent e) =>
_googleMapState.onMarkerDragEnd(e.value, e.position));
_googleMapsFlutterPlatform.onInfoWindowTap(mapId: mapId).listen(
GoogleMapsFlutterPlatform.instance.onInfoWindowTap(mapId: mapId).listen(
(InfoWindowTapEvent e) => _googleMapState.onInfoWindowTap(e.value));
_googleMapsFlutterPlatform
GoogleMapsFlutterPlatform.instance
.onPolylineTap(mapId: mapId)
.listen((PolylineTapEvent e) => _googleMapState.onPolylineTap(e.value));
_googleMapsFlutterPlatform
GoogleMapsFlutterPlatform.instance
.onPolygonTap(mapId: mapId)
.listen((PolygonTapEvent e) => _googleMapState.onPolygonTap(e.value));
_googleMapsFlutterPlatform
GoogleMapsFlutterPlatform.instance
.onCircleTap(mapId: mapId)
.listen((CircleTapEvent e) => _googleMapState.onCircleTap(e.value));
_googleMapsFlutterPlatform
GoogleMapsFlutterPlatform.instance
.onTap(mapId: mapId)
.listen((MapTapEvent e) => _googleMapState.onTap(e.position));
_googleMapsFlutterPlatform.onLongPress(mapId: mapId).listen(
GoogleMapsFlutterPlatform.instance.onLongPress(mapId: mapId).listen(
(MapLongPressEvent e) => _googleMapState.onLongPress(e.position));
}

Expand All @@ -100,7 +97,7 @@ class GoogleMapController {
/// The returned [Future] completes after listeners have been notified.
Future<void> _updateMapOptions(Map<String, dynamic> optionsUpdate) {
assert(optionsUpdate != null);
return _googleMapsFlutterPlatform.updateMapOptions(optionsUpdate,
return GoogleMapsFlutterPlatform.instance.updateMapOptions(optionsUpdate,
mapId: mapId);
}

Expand All @@ -112,7 +109,7 @@ class GoogleMapController {
/// The returned [Future] completes after listeners have been notified.
Future<void> _updateMarkers(MarkerUpdates markerUpdates) {
assert(markerUpdates != null);
return _googleMapsFlutterPlatform.updateMarkers(markerUpdates,
return GoogleMapsFlutterPlatform.instance.updateMarkers(markerUpdates,
mapId: mapId);
}

Expand All @@ -124,7 +121,7 @@ class GoogleMapController {
/// The returned [Future] completes after listeners have been notified.
Future<void> _updatePolygons(PolygonUpdates polygonUpdates) {
assert(polygonUpdates != null);
return _googleMapsFlutterPlatform.updatePolygons(polygonUpdates,
return GoogleMapsFlutterPlatform.instance.updatePolygons(polygonUpdates,
mapId: mapId);
}

Expand All @@ -136,7 +133,7 @@ class GoogleMapController {
/// The returned [Future] completes after listeners have been notified.
Future<void> _updatePolylines(PolylineUpdates polylineUpdates) {
assert(polylineUpdates != null);
return _googleMapsFlutterPlatform.updatePolylines(polylineUpdates,
return GoogleMapsFlutterPlatform.instance.updatePolylines(polylineUpdates,
mapId: mapId);
}

Expand All @@ -148,7 +145,7 @@ class GoogleMapController {
/// The returned [Future] completes after listeners have been notified.
Future<void> _updateCircles(CircleUpdates circleUpdates) {
assert(circleUpdates != null);
return _googleMapsFlutterPlatform.updateCircles(circleUpdates,
return GoogleMapsFlutterPlatform.instance.updateCircles(circleUpdates,
mapId: mapId);
}

Expand All @@ -159,7 +156,7 @@ class GoogleMapController {
///
/// The returned [Future] completes after listeners have been notified.
Future<void> _updateTileOverlays(Set<TileOverlay> newTileOverlays) {
return _googleMapsFlutterPlatform.updateTileOverlays(
return GoogleMapsFlutterPlatform.instance.updateTileOverlays(
newTileOverlays: newTileOverlays, mapId: mapId);
}

Expand All @@ -172,7 +169,7 @@ class GoogleMapController {
/// should implement an on-disk cache.
Future<void> clearTileCache(TileOverlayId tileOverlayId) async {
assert(tileOverlayId != null);
return _googleMapsFlutterPlatform.clearTileCache(tileOverlayId,
return GoogleMapsFlutterPlatform.instance.clearTileCache(tileOverlayId,
mapId: mapId);
}

Expand All @@ -181,15 +178,15 @@ class GoogleMapController {
/// The returned [Future] completes after the change has been started on the
/// platform side.
Future<void> animateCamera(CameraUpdate cameraUpdate) {
return _googleMapsFlutterPlatform.animateCamera(cameraUpdate, mapId: mapId);
return GoogleMapsFlutterPlatform.instance.animateCamera(cameraUpdate, mapId: mapId);
}

/// Changes the map camera position.
///
/// The returned [Future] completes after the change has been made on the
/// platform side.
Future<void> moveCamera(CameraUpdate cameraUpdate) {
return _googleMapsFlutterPlatform.moveCamera(cameraUpdate, mapId: mapId);
return GoogleMapsFlutterPlatform.instance.moveCamera(cameraUpdate, mapId: mapId);
}

/// Sets the styling of the base map.
Expand All @@ -206,12 +203,12 @@ class GoogleMapController {
/// and [Android](https://developers.google.com/maps/documentation/android-sdk/style-reference)
/// style reference for more information regarding the supported styles.
Future<void> setMapStyle(String mapStyle) {
return _googleMapsFlutterPlatform.setMapStyle(mapStyle, mapId: mapId);
return GoogleMapsFlutterPlatform.instance.setMapStyle(mapStyle, mapId: mapId);
}

/// Return [LatLngBounds] defining the region that is visible in a map.
Future<LatLngBounds> getVisibleRegion() {
return _googleMapsFlutterPlatform.getVisibleRegion(mapId: mapId);
return GoogleMapsFlutterPlatform.instance.getVisibleRegion(mapId: mapId);
}

/// Return [ScreenCoordinate] of the [LatLng] in the current map view.
Expand All @@ -220,15 +217,15 @@ class GoogleMapController {
/// Screen location is in screen pixels (not display pixels) with respect to the top left corner
/// of the map, not necessarily of the whole screen.
Future<ScreenCoordinate> getScreenCoordinate(LatLng latLng) {
return _googleMapsFlutterPlatform.getScreenCoordinate(latLng, mapId: mapId);
return GoogleMapsFlutterPlatform.instance.getScreenCoordinate(latLng, mapId: mapId);
}

/// Returns [LatLng] corresponding to the [ScreenCoordinate] in the current map view.
///
/// Returned [LatLng] corresponds to a screen location. The screen location is specified in screen
/// pixels (not display pixels) relative to the top left of the map, not top left of the whole screen.
Future<LatLng> getLatLng(ScreenCoordinate screenCoordinate) {
return _googleMapsFlutterPlatform.getLatLng(screenCoordinate, mapId: mapId);
return GoogleMapsFlutterPlatform.instance.getLatLng(screenCoordinate, mapId: mapId);
}

/// Programmatically show the Info Window for a [Marker].
Expand All @@ -241,7 +238,7 @@ class GoogleMapController {
/// * [isMarkerInfoWindowShown] to check if the Info Window is showing.
Future<void> showMarkerInfoWindow(MarkerId markerId) {
assert(markerId != null);
return _googleMapsFlutterPlatform.showMarkerInfoWindow(markerId,
return GoogleMapsFlutterPlatform.instance.showMarkerInfoWindow(markerId,
mapId: mapId);
}

Expand All @@ -255,7 +252,7 @@ class GoogleMapController {
/// * [isMarkerInfoWindowShown] to check if the Info Window is showing.
Future<void> hideMarkerInfoWindow(MarkerId markerId) {
assert(markerId != null);
return _googleMapsFlutterPlatform.hideMarkerInfoWindow(markerId,
return GoogleMapsFlutterPlatform.instance.hideMarkerInfoWindow(markerId,
mapId: mapId);
}

Expand All @@ -269,22 +266,22 @@ class GoogleMapController {
/// * [hideMarkerInfoWindow] to hide the Info Window.
Future<bool> isMarkerInfoWindowShown(MarkerId markerId) {
assert(markerId != null);
return _googleMapsFlutterPlatform.isMarkerInfoWindowShown(markerId,
return GoogleMapsFlutterPlatform.instance.isMarkerInfoWindowShown(markerId,
mapId: mapId);
}

/// Returns the current zoom level of the map
Future<double> getZoomLevel() {
return _googleMapsFlutterPlatform.getZoomLevel(mapId: mapId);
return GoogleMapsFlutterPlatform.instance.getZoomLevel(mapId: mapId);
}

/// Returns the image bytes of the map
Future<Uint8List?> takeSnapshot() {
return _googleMapsFlutterPlatform.takeSnapshot(mapId: mapId);
return GoogleMapsFlutterPlatform.instance.takeSnapshot(mapId: mapId);
}

/// Disposes of the platform resources
void dispose() {
_googleMapsFlutterPlatform.dispose(mapId: mapId);
GoogleMapsFlutterPlatform.instance.dispose(mapId: mapId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ class _GoogleMapState extends State<GoogleMap> {
@override
Widget build(BuildContext context) {
final Map<String, dynamic> creationParams = <String, dynamic>{
'initialCameraPosition': widget.initialCameraPosition?.toMap(),
'initialCameraPosition': widget.initialCameraPosition.toMap(),
'options': _googleMapOptions.toMap(),
'markersToAdd': serializeMarkerSet(widget.markers),
'polygonsToAdd': serializePolygonSet(widget.polygons),
Expand All @@ -258,7 +258,7 @@ class _GoogleMapState extends State<GoogleMap> {
'tileOverlaysToAdd': serializeTileOverlaySet(widget.tileOverlays),
};

return _googleMapsFlutterPlatform.buildView(
return GoogleMapsFlutterPlatform.instance.buildView(
creationParams,
widget.gestureRecognizers,
onPlatformViewCreated,
Expand Down Expand Up @@ -400,7 +400,7 @@ class _GoogleMapState extends State<GoogleMap> {
if (polyline == null) {
throw UnknownMapObjectIDError('polyline', 'onTap');
}
final onTap = polyline?.onTap;
final onTap = polyline.onTap;
if (onTap != null) {
onTap();
}
Expand All @@ -412,7 +412,7 @@ class _GoogleMapState extends State<GoogleMap> {
if (circle == null) {
throw UnknownMapObjectIDError('marker', 'onTap');
}
final onTap = circle?.onTap;
final onTap = circle.onTap;
if (onTap != null) {
onTap();
}
Expand All @@ -424,7 +424,7 @@ class _GoogleMapState extends State<GoogleMap> {
if (marker == null) {
throw UnknownMapObjectIDError('marker', 'InfoWindow onTap');
}
final onTap = marker.infoWindow?.onTap;
final onTap = marker.infoWindow.onTap;
if (onTap != null) {
onTap();
}
Expand Down Expand Up @@ -512,7 +512,7 @@ class _GoogleMapOptions {
'compassEnabled': compassEnabled,
'mapToolbarEnabled': mapToolbarEnabled,
'cameraTargetBounds': cameraTargetBounds.toJson(),
'mapType': mapType?.index,
'mapType': mapType.index,
'minMaxZoomPreference': minMaxZoomPreference.toJson(),
'rotateGesturesEnabled': rotateGesturesEnabled,
'scrollGesturesEnabled': scrollGesturesEnabled,
Expand All @@ -524,10 +524,10 @@ class _GoogleMapOptions {
'myLocationEnabled': myLocationEnabled,
'myLocationButtonEnabled': myLocationButtonEnabled,
'padding': <double>[
padding?.top,
padding?.left,
padding?.bottom,
padding?.right,
padding.top,
padding.left,
padding.bottom,
padding.right,
],
'indoorEnabled': indoorViewEnabled,
'trafficEnabled': trafficEnabled,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ dev_dependencies:
test: ^1.16.0-nullsafety.17
pedantic: ^1.10.0-nullsafety.3
plugin_platform_interface: ^1.1.0-nullsafety.2
mockito: ^5.0.0-nullsafety.7
stream_transform: ^2.0.0-nullsafety.0

flutter:
plugin:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ void main() {
final Circle c1 = Circle(circleId: CircleId("circle_1"));

await tester.pumpWidget(_mapWithCircles(<Circle>{c1}));
await tester.pumpWidget(_mapWithCircles(null));
await tester.pumpWidget(_mapWithCircles(<Circle>{}));

final FakePlatformGoogleMap platformGoogleMap =
fakePlatformViewsController.lastCreatedView!;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ class FakePlatformGoogleMap {
}
final List<dynamic> markersData = markers;
final Set<Marker> result = <Marker>{};
for (Map<dynamic, dynamic> markerData in markersData as Iterable<Map<dynamic, dynamic>>) {
for (Map<dynamic, dynamic> markerData in markersData.cast<Map<dynamic, dynamic>>()) {
final String markerId = markerData['markerId'];
final double alpha = markerData['alpha'];
final bool draggable = markerData['draggable'];
Expand Down Expand Up @@ -191,7 +191,7 @@ class FakePlatformGoogleMap {
}
final List<dynamic> polygonsData = polygons;
final Set<Polygon> result = <Polygon>{};
for (Map<dynamic, dynamic> polygonData in polygonsData as Iterable<Map<dynamic, dynamic>>) {
for (Map<dynamic, dynamic> polygonData in polygonsData.cast<Map<dynamic, dynamic>>()) {
final String polygonId = polygonData['polygonId'];
final bool visible = polygonData['visible'];
final bool geodesic = polygonData['geodesic'];
Expand Down Expand Up @@ -250,7 +250,7 @@ class FakePlatformGoogleMap {
}
final List<dynamic> polylinesData = polylines;
final Set<Polyline> result = <Polyline>{};
for (Map<dynamic, dynamic> polylineData in polylinesData as Iterable<Map<dynamic, dynamic>>) {
for (Map<dynamic, dynamic> polylineData in polylinesData.cast<Map<dynamic, dynamic>>()) {
final String polylineId = polylineData['polylineId'];
final bool visible = polylineData['visible'];
final bool geodesic = polylineData['geodesic'];
Expand Down Expand Up @@ -315,7 +315,7 @@ class FakePlatformGoogleMap {
}
final List<dynamic> circlesData = circles;
final Set<Circle> result = <Circle>{};
for (Map<dynamic, dynamic> circleData in circlesData as Iterable<Map<dynamic, dynamic>>) {
for (Map<dynamic, dynamic> circleData in circlesData.cast<Map<dynamic, dynamic>>()) {
final String circleId = circleData['circleId'];
final bool visible = circleData['visible'];
final double radius = circleData['radius'];
Expand Down
Loading