From a9814102ee15cfa146c62578105ff03a0e39dd39 Mon Sep 17 00:00:00 2001 From: Joonas Kerttula Date: Mon, 9 Dec 2024 16:55:38 +0200 Subject: [PATCH] chore: simplify platform interface implementation --- lib/src/google_maps_auto_view_controller.dart | 121 +-- lib/src/google_maps_image_registry.dart | 19 +- lib/src/google_maps_map_view.dart | 14 +- lib/src/google_maps_map_view_controller.dart | 88 ++- lib/src/google_maps_navigation_view.dart | 12 +- ...oogle_maps_navigation_view_controller.dart | 34 +- lib/src/google_navigation_flutter.dart | 44 +- .../google_navigation_flutter_android.dart | 51 +- lib/src/google_navigation_flutter_ios.dart | 37 +- ...navigation_flutter_platform_interface.dart | 725 +----------------- ..._auto_view_api.dart => auto_view_api.dart} | 271 ++++--- .../{common_image_api.dart => image_api.dart} | 11 +- ...common_view_api.dart => map_view_api.dart} | 206 ++--- lib/src/method_channel/method_channel.dart | 7 +- ...mmon_session_api.dart => session_api.dart} | 62 +- .../google_navigation_flutter_navigator.dart | 101 ++- .../google_navigation_flutter_simulator.dart | 23 +- 17 files changed, 579 insertions(+), 1247 deletions(-) rename lib/src/method_channel/{common_auto_view_api.dart => auto_view_api.dart} (75%) rename lib/src/method_channel/{common_image_api.dart => image_api.dart} (91%) rename lib/src/method_channel/{common_view_api.dart => map_view_api.dart} (87%) rename lib/src/method_channel/{common_session_api.dart => session_api.dart} (95%) diff --git a/lib/src/google_maps_auto_view_controller.dart b/lib/src/google_maps_auto_view_controller.dart index ae332e7..62584e9 100644 --- a/lib/src/google_maps_auto_view_controller.dart +++ b/lib/src/google_maps_auto_view_controller.dart @@ -17,19 +17,19 @@ import 'google_navigation_flutter_platform_interface.dart'; class GoogleMapsAutoViewController { GoogleMapsAutoViewController() { - GoogleMapsNavigationPlatform.instance.initializeAutoViewEventAPI(); + GoogleMapsNavigationPlatform.instance.autoAPI.ensureAutoViewApiSetUp(); } /// Change status of my location enabled. /// Future setMyLocationEnabled(bool enabled) { - return GoogleMapsNavigationPlatform.instance - .setMyLocationEnabledForAuto(enabled: enabled); + return GoogleMapsNavigationPlatform.instance.autoAPI + .setMyLocationEnabled(enabled: enabled); } /// This method returns the current map type of the Google Maps view instance. Future getMapType() { - return GoogleMapsNavigationPlatform.instance.getMapTypeForAuto(); + return GoogleMapsNavigationPlatform.instance.autoAPI.getMapType(); } /// Changes the type of the map being displayed on the Google Maps view. @@ -44,8 +44,8 @@ class GoogleMapsAutoViewController { /// _mapViewController.changeMapType(MapType.satellite); /// ``` Future setMapType({required MapType mapType}) async { - return GoogleMapsNavigationPlatform.instance - .setMapTypeForAuto(mapType: mapType); + return GoogleMapsNavigationPlatform.instance.autoAPI + .setMapType(mapType: mapType); } /// Sets the styling of the base map using a string containing JSON. @@ -56,13 +56,13 @@ class GoogleMapsAutoViewController { /// https://developers.google.com/maps/documentation/ios-sdk/styling /// https://developers.google.com/maps/documentation/android-sdk/styling Future setMapStyle(String? styleJson) async { - return GoogleMapsNavigationPlatform.instance.setMapStyleForAuto(styleJson); + return GoogleMapsNavigationPlatform.instance.autoAPI.setMapStyle(styleJson); } /// Gets whether the my location is enabled or disabled. /// Future isMyLocationEnabled() async { - return GoogleMapsNavigationPlatform.instance.isMyLocationEnabledForAuto(); + return GoogleMapsNavigationPlatform.instance.autoAPI.isMyLocationEnabled(); } /// Ask the camera to follow the user's location. @@ -71,23 +71,23 @@ class GoogleMapsAutoViewController { /// and optional [zoomLevel] to control the map zoom. Future followMyLocation(CameraPerspective perspective, {double? zoomLevel}) async { - return GoogleMapsNavigationPlatform.instance.followMyLocationForAuto( - perspective: perspective, zoomLevel: zoomLevel); + return GoogleMapsNavigationPlatform.instance.autoAPI + .followMyLocation(perspective: perspective, zoomLevel: zoomLevel); } /// Gets user's current location. Future getMyLocation() async { - return GoogleMapsNavigationPlatform.instance.getMyLocationForAuto(); + return GoogleMapsNavigationPlatform.instance.autoAPI.getMyLocation(); } /// Gets the current visible map region or camera bounds. Future getVisibleRegion() async { - return GoogleMapsNavigationPlatform.instance.getVisibleRegionForAuto(); + return GoogleMapsNavigationPlatform.instance.autoAPI.getVisibleRegion(); } /// Gets the current position of the camera. Future getCameraPosition() async { - return GoogleMapsNavigationPlatform.instance.getCameraPositionForAuto(); + return GoogleMapsNavigationPlatform.instance.autoAPI.getCameraPosition(); } /// Animates the movement of the camera from the current position @@ -112,7 +112,7 @@ class GoogleMapsAutoViewController { /// See also [moveCamera], [followMyLocation]. Future animateCamera(CameraUpdate cameraUpdate, {Duration? duration, AnimationFinishedCallback? onFinished}) { - return GoogleMapsNavigationPlatform.instance.animateCameraForAuto( + return GoogleMapsNavigationPlatform.instance.autoAPI.animateCamera( cameraUpdate: cameraUpdate, duration: duration?.inMilliseconds, onFinished: onFinished); @@ -124,28 +124,28 @@ class GoogleMapsAutoViewController { /// See [CameraUpdate] for more information /// on how to create different camera movements. Future moveCamera(CameraUpdate cameraUpdate) { - return GoogleMapsNavigationPlatform.instance - .moveCameraForAuto(cameraUpdate: cameraUpdate); + return GoogleMapsNavigationPlatform.instance.autoAPI + .moveCamera(cameraUpdate: cameraUpdate); } /// Returns the minimum zoom level preference from the map view. /// If minimum zoom preference is not set previously, returns minimum possible /// zoom level for the current map type. Future getMinZoomPreference() { - return GoogleMapsNavigationPlatform.instance.getMinZoomPreferenceForAuto(); + return GoogleMapsNavigationPlatform.instance.autoAPI.getMinZoomPreference(); } /// Returns the maximum zoom level preference from the map view. /// If maximum zoom preference is not set previously, returns maximum possible /// zoom level for the current map type. Future getMaxZoomPreference() { - return GoogleMapsNavigationPlatform.instance.getMaxZoomPreferenceForAuto(); + return GoogleMapsNavigationPlatform.instance.autoAPI.getMaxZoomPreference(); } /// Removes any previously specified upper and lower zoom bounds. Future resetMinMaxZoomPreference() { - return GoogleMapsNavigationPlatform.instance - .resetMinMaxZoomPreferenceForAuto(); + return GoogleMapsNavigationPlatform.instance.autoAPI + .resetMinMaxZoomPreference(); } /// Sets a preferred lower bound for the camera zoom. @@ -157,8 +157,8 @@ class GoogleMapsAutoViewController { /// Throws [MinZoomRangeException] if [minZoomPreference] is /// greater than maximum zoom lavel. Future setMinZoomPreference(double minZoomPreference) { - return GoogleMapsNavigationPlatform.instance - .setMinZoomPreferenceForAuto(minZoomPreference: minZoomPreference); + return GoogleMapsNavigationPlatform.instance.autoAPI + .setMinZoomPreference(minZoomPreference: minZoomPreference); } /// Sets a preferred upper bound for the camera zoom. @@ -172,19 +172,19 @@ class GoogleMapsAutoViewController { /// Throws [MaxZoomRangeException] if [maxZoomPreference] is /// less than minimum zoom lavel. Future setMaxZoomPreference(double maxZoomPreference) { - return GoogleMapsNavigationPlatform.instance - .setMaxZoomPreferenceForAuto(maxZoomPreference: maxZoomPreference); + return GoogleMapsNavigationPlatform.instance.autoAPI + .setMaxZoomPreference(maxZoomPreference: maxZoomPreference); } /// Retrieves all markers that have been added to the map view. Future> getMarkers() { - return GoogleMapsNavigationPlatform.instance.getMarkersForAuto(); + return GoogleMapsNavigationPlatform.instance.autoAPI.getMarkers(); } /// Add markers to the map view. Future> addMarkers(List markerOptions) { - return GoogleMapsNavigationPlatform.instance - .addMarkersForAuto(markerOptions: markerOptions); + return GoogleMapsNavigationPlatform.instance.autoAPI + .addMarkers(markerOptions: markerOptions); } /// Update markers to the map view. @@ -193,8 +193,8 @@ class GoogleMapsAutoViewController { /// more markers that have not been added to the map view via [addMarkers] or /// contains markers that have already been removed from the map view. Future> updateMarkers(List markers) async { - return GoogleMapsNavigationPlatform.instance - .updateMarkersForAuto(markers: markers); + return GoogleMapsNavigationPlatform.instance.autoAPI + .updateMarkers(markers: markers); } /// Remove markers from the map view. @@ -203,24 +203,24 @@ class GoogleMapsAutoViewController { /// more markers that have not been added to the map view via [addMarkers] or /// contains markers that have already been removed from the map view. Future removeMarkers(List markers) async { - return GoogleMapsNavigationPlatform.instance - .removeMarkersForAuto(markers: markers); + return GoogleMapsNavigationPlatform.instance.autoAPI + .removeMarkers(markers: markers); } /// Remove all markers from the map view. Future clearMarkers() { - return GoogleMapsNavigationPlatform.instance.clearMarkersForAuto(); + return GoogleMapsNavigationPlatform.instance.autoAPI.clearMarkers(); } /// Retrieves all polygons that have been added to the map view. Future> getPolygons() { - return GoogleMapsNavigationPlatform.instance.getPolygonsForAuto(); + return GoogleMapsNavigationPlatform.instance.autoAPI.getPolygons(); } /// Add polygons to the map view. Future> addPolygons(List polygonOptions) { - return GoogleMapsNavigationPlatform.instance - .addPolygonsForAuto(polygonOptions: polygonOptions); + return GoogleMapsNavigationPlatform.instance.autoAPI + .addPolygons(polygonOptions: polygonOptions); } /// Update polygons to the map view. @@ -229,8 +229,8 @@ class GoogleMapsAutoViewController { /// polygon that has not beed added to the map view via [addPolygons] or /// contains polygon that has already been removed from the map view. Future> updatePolygons(List polygons) async { - return GoogleMapsNavigationPlatform.instance - .updatePolygonsForAuto(polygons: polygons); + return GoogleMapsNavigationPlatform.instance.autoAPI + .updatePolygons(polygons: polygons); } /// Remove polygons from the map view. @@ -239,24 +239,24 @@ class GoogleMapsAutoViewController { /// polygon that has not beed added to the map view via [addPolygons] or /// contains polygon that has already been removed from the map view. Future removePolygons(List polygons) async { - return GoogleMapsNavigationPlatform.instance - .removePolygonsForAuto(polygons: polygons); + return GoogleMapsNavigationPlatform.instance.autoAPI + .removePolygons(polygons: polygons); } /// Remove all polygons from the map view. Future clearPolygons() { - return GoogleMapsNavigationPlatform.instance.clearPolygonsForAuto(); + return GoogleMapsNavigationPlatform.instance.autoAPI.clearPolygons(); } /// Retrieves all polylines that have been added to the map view. Future> getPolylines() { - return GoogleMapsNavigationPlatform.instance.getPolylinesForAuto(); + return GoogleMapsNavigationPlatform.instance.autoAPI.getPolylines(); } /// Add polylines to the map view. Future> addPolylines(List polylineOptions) { - return GoogleMapsNavigationPlatform.instance - .addPolylinesForAuto(polylineOptions: polylineOptions); + return GoogleMapsNavigationPlatform.instance.autoAPI + .addPolylines(polylineOptions: polylineOptions); } /// Update polylines to the map view. @@ -265,8 +265,8 @@ class GoogleMapsAutoViewController { /// polyline that has not beed added to the map view via [addPolylines] or /// contains polyline that has already been removed from the map view. Future> updatePolylines(List polylines) async { - return GoogleMapsNavigationPlatform.instance - .updatePolylinesForAuto(polylines: polylines); + return GoogleMapsNavigationPlatform.instance.autoAPI + .updatePolylines(polylines: polylines); } /// Remove polylines from the map view. @@ -275,24 +275,24 @@ class GoogleMapsAutoViewController { /// polyline that has not beed added to the map view via [addPolylines] or /// contains polyline that has already been removed from the map view. Future removePolylines(List polylines) async { - return GoogleMapsNavigationPlatform.instance - .removePolylinesForAuto(polylines: polylines); + return GoogleMapsNavigationPlatform.instance.autoAPI + .removePolylines(polylines: polylines); } /// Remove all polylines from the map view. Future clearPolylines() { - return GoogleMapsNavigationPlatform.instance.clearPolylinesForAuto(); + return GoogleMapsNavigationPlatform.instance.autoAPI.clearPolylines(); } /// Gets all circles from the map view. Future> getCircles() { - return GoogleMapsNavigationPlatform.instance.getCirclesForAuto(); + return GoogleMapsNavigationPlatform.instance.autoAPI.getCircles(); } /// Add circles to the map view. Future> addCircles(List options) { - return GoogleMapsNavigationPlatform.instance - .addCirclesForAuto(options: options); + return GoogleMapsNavigationPlatform.instance.autoAPI + .addCircles(options: options); } /// Update circles to the map view. @@ -301,8 +301,8 @@ class GoogleMapsAutoViewController { /// more circles that have not been added to the map view via [addCircles] or /// contains circles that have already been removed from the map view. Future> updateCircles(List circles) async { - return GoogleMapsNavigationPlatform.instance - .updateCirclesForAuto(circles: circles); + return GoogleMapsNavigationPlatform.instance.autoAPI + .updateCircles(circles: circles); } /// Remove circles from the map view. @@ -311,27 +311,28 @@ class GoogleMapsAutoViewController { /// more circles that have not been added to the map view via [addCircles] or /// contains circles that have already been removed from the map view. Future removeCircles(List circles) async { - return GoogleMapsNavigationPlatform.instance - .removeCirclesForAuto(circles: circles); + return GoogleMapsNavigationPlatform.instance.autoAPI + .removeCircles(circles: circles); } /// Remove all circles from the map view. Future clearCircles() { - return GoogleMapsNavigationPlatform.instance.clearCirclesForAuto(); + return GoogleMapsNavigationPlatform.instance.autoAPI.clearCircles(); } /// Remove all markers, polylines, polygons, overlays, etc from the map view. Future clear() { - return GoogleMapsNavigationPlatform.instance.clearForAuto(); + return GoogleMapsNavigationPlatform.instance.autoAPI.clear(); } Future isAutoScreenAvailable() { - return GoogleMapsNavigationPlatform.instance.isAutoScreenAvailable(); + return GoogleMapsNavigationPlatform.instance.autoAPI + .isAutoScreenAvailable(); } void listenForCustomNavigationAutoEvents( void Function(CustomNavigationAutoEvent event) func) { - GoogleMapsNavigationPlatform.instance + GoogleMapsNavigationPlatform.instance.autoAPI .getCustomNavigationAutoEventStream() .listen((CustomNavigationAutoEvent event) { func(event); @@ -340,7 +341,7 @@ class GoogleMapsAutoViewController { void listenForAutoScreenAvailibilityChangedEvent( void Function(AutoScreenAvailabilityChangedEvent event) func) { - GoogleMapsNavigationPlatform.instance + GoogleMapsNavigationPlatform.instance.autoAPI .getAutoScreenAvailabilityChangedEventStream() .listen((AutoScreenAvailabilityChangedEvent event) { func(event); diff --git a/lib/src/google_maps_image_registry.dart b/lib/src/google_maps_image_registry.dart index be4fa8e..1485436 100644 --- a/lib/src/google_maps_image_registry.dart +++ b/lib/src/google_maps_image_registry.dart @@ -35,30 +35,33 @@ Future registerBitmapImage( double imagePixelRatio = 1.0, double? width, double? height}) { - return GoogleMapsNavigationPlatform.instance.registerBitmapImage( - bitmap: bitmap.buffer.asUint8List(), - imagePixelRatio: imagePixelRatio, - width: width, - height: height); + return GoogleMapsNavigationPlatform.instance.imageRegistryAPI + .registerBitmapImage( + bitmap: bitmap.buffer.asUint8List(), + imagePixelRatio: imagePixelRatio, + width: width, + height: height); } /// Delete previously registered bitmap from image registry. /// {@category Image Registry} Future unregisterImage(ImageDescriptor imageDescriptor) { - return GoogleMapsNavigationPlatform.instance + return GoogleMapsNavigationPlatform.instance.imageRegistryAPI .unregisterImage(imageDescriptor: imageDescriptor); } /// Get all registered bitmaps from image registry. /// {@category Image Registry} Future> getRegisteredImages() { - return GoogleMapsNavigationPlatform.instance.getRegisteredImages(); + return GoogleMapsNavigationPlatform.instance.imageRegistryAPI + .getRegisteredImages(); } /// Remove all registered bitmaps from image registry. /// {@category Image Registry} Future clearRegisteredImages() { - return GoogleMapsNavigationPlatform.instance.clearRegisteredImages(); + return GoogleMapsNavigationPlatform.instance.imageRegistryAPI + .clearRegisteredImages(); } /// [registerBitmapImage] failed to decode bitmap from byte array. diff --git a/lib/src/google_maps_map_view.dart b/lib/src/google_maps_map_view.dart index c29a809..03dcdfe 100644 --- a/lib/src/google_maps_map_view.dart +++ b/lib/src/google_maps_map_view.dart @@ -288,7 +288,7 @@ abstract class MapViewState extends State { @protected void initMapViewListeners(int viewId) { if (widget.onMapClicked != null) { - GoogleMapsNavigationPlatform.instance + GoogleMapsNavigationPlatform.instance.viewAPI .getMapClickEventStream(viewId: viewId) .listen((MapClickEvent event) { widget.onMapClicked!(event.target); @@ -296,14 +296,14 @@ abstract class MapViewState extends State { } if (widget.onMapLongClicked != null) { - GoogleMapsNavigationPlatform.instance + GoogleMapsNavigationPlatform.instance.viewAPI .getMapLongClickEventStream(viewId: viewId) .listen((MapLongClickEvent event) { widget.onMapLongClicked!(event.target); }); } - GoogleMapsNavigationPlatform.instance + GoogleMapsNavigationPlatform.instance.viewAPI .getMarkerEventStream(viewId: viewId) .listen((MarkerEvent event) { switch (event.eventType) { @@ -318,7 +318,7 @@ abstract class MapViewState extends State { } }); - GoogleMapsNavigationPlatform.instance + GoogleMapsNavigationPlatform.instance.viewAPI .getMarkerDragEventStream(viewId: viewId) .listen((MarkerDragEvent event) { switch (event.eventType) { @@ -330,19 +330,19 @@ abstract class MapViewState extends State { widget.onMarkerDragStart?.call(event.markerId, event.position); } - GoogleMapsNavigationPlatform.instance + GoogleMapsNavigationPlatform.instance.viewAPI .getPolygonClickedEventStream(viewId: viewId) .listen((PolygonClickedEvent event) { widget.onPolygonClicked?.call(event.polygonId); }); - GoogleMapsNavigationPlatform.instance + GoogleMapsNavigationPlatform.instance.viewAPI .getPolylineClickedEventStream(viewId: viewId) .listen((PolylineClickedEvent event) { widget.onPolylineClicked?.call(event.polylineId); }); - GoogleMapsNavigationPlatform.instance + GoogleMapsNavigationPlatform.instance.viewAPI .getCircleClickedEventStream(viewId: viewId) .listen((CircleClickedEvent event) { widget.onCircleClicked?.call(event.circleId); diff --git a/lib/src/google_maps_map_view_controller.dart b/lib/src/google_maps_map_view_controller.dart index fa1604b..5c07dce 100644 --- a/lib/src/google_maps_map_view_controller.dart +++ b/lib/src/google_maps_map_view_controller.dart @@ -38,13 +38,14 @@ class GoogleMapViewController { /// Change status of my location enabled. /// Future setMyLocationEnabled(bool enabled) { - return GoogleMapsNavigationPlatform.instance + return GoogleMapsNavigationPlatform.instance.viewAPI .setMyLocationEnabled(viewId: _viewId, enabled: enabled); } /// This method returns the current map type of the Google Maps view instance. Future getMapType() { - return GoogleMapsNavigationPlatform.instance.getMapType(viewId: _viewId); + return GoogleMapsNavigationPlatform.instance.viewAPI + .getMapType(viewId: _viewId); } /// Changes the type of the map being displayed on the Google Maps view. @@ -59,7 +60,7 @@ class GoogleMapViewController { /// _mapViewController.changeMapType(MapType.satellite); /// ``` Future setMapType({required MapType mapType}) async { - return GoogleMapsNavigationPlatform.instance + return GoogleMapsNavigationPlatform.instance.viewAPI .setMapType(viewId: _viewId, mapType: mapType); } @@ -71,14 +72,14 @@ class GoogleMapViewController { /// https://developers.google.com/maps/documentation/ios-sdk/styling /// https://developers.google.com/maps/documentation/android-sdk/styling Future setMapStyle(String? styleJson) async { - return GoogleMapsNavigationPlatform.instance + return GoogleMapsNavigationPlatform.instance.viewAPI .setMapStyle(_viewId, styleJson); } /// Gets whether the my location is enabled or disabled. /// Future isMyLocationEnabled() async { - return GoogleMapsNavigationPlatform.instance + return GoogleMapsNavigationPlatform.instance.viewAPI .isMyLocationEnabled(viewId: _viewId); } @@ -88,24 +89,25 @@ class GoogleMapViewController { /// and optional [zoomLevel] to control the map zoom. Future followMyLocation(CameraPerspective perspective, {double? zoomLevel}) async { - return GoogleMapsNavigationPlatform.instance.followMyLocation( + return GoogleMapsNavigationPlatform.instance.viewAPI.followMyLocation( viewId: _viewId, perspective: perspective, zoomLevel: zoomLevel); } /// Gets user's current location. Future getMyLocation() async { - return GoogleMapsNavigationPlatform.instance.getMyLocation(viewId: _viewId); + return GoogleMapsNavigationPlatform.instance.viewAPI + .getMyLocation(viewId: _viewId); } /// Gets the current visible map region or camera bounds. Future getVisibleRegion() async { - return GoogleMapsNavigationPlatform.instance + return GoogleMapsNavigationPlatform.instance.viewAPI .getVisibleRegion(viewId: _viewId); } /// Gets the current position of the camera. Future getCameraPosition() async { - return GoogleMapsNavigationPlatform.instance + return GoogleMapsNavigationPlatform.instance.viewAPI .getCameraPosition(viewId: _viewId); } @@ -131,7 +133,7 @@ class GoogleMapViewController { /// See also [moveCamera], [followMyLocation]. Future animateCamera(CameraUpdate cameraUpdate, {Duration? duration, AnimationFinishedCallback? onFinished}) { - return GoogleMapsNavigationPlatform.instance.animateCamera( + return GoogleMapsNavigationPlatform.instance.viewAPI.animateCamera( viewId: _viewId, cameraUpdate: cameraUpdate, duration: duration?.inMilliseconds, @@ -144,13 +146,13 @@ class GoogleMapViewController { /// See [CameraUpdate] for more information /// on how to create different camera movements. Future moveCamera(CameraUpdate cameraUpdate) { - return GoogleMapsNavigationPlatform.instance + return GoogleMapsNavigationPlatform.instance.viewAPI .moveCamera(viewId: _viewId, cameraUpdate: cameraUpdate); } /// Is the recenter button enabled. Future isRecenterButtonEnabled() { - return GoogleMapsNavigationPlatform.instance + return GoogleMapsNavigationPlatform.instance.viewAPI .isRecenterButtonEnabled(viewId: _viewId); } @@ -158,7 +160,8 @@ class GoogleMapViewController { /// /// By default, the recenter button is enabled. Future setRecenterButtonEnabled(bool enabled) { - return GoogleMapsNavigationPlatform.instance.setRecenterButtonEnabled( + return GoogleMapsNavigationPlatform.instance.viewAPI + .setRecenterButtonEnabled( viewId: _viewId, enabled: enabled, ); @@ -168,7 +171,7 @@ class GoogleMapViewController { /// If minimum zoom preference is not set previously, returns minimum possible /// zoom level for the current map type. Future getMinZoomPreference() { - return GoogleMapsNavigationPlatform.instance + return GoogleMapsNavigationPlatform.instance.viewAPI .getMinZoomPreference(viewId: _viewId); } @@ -176,13 +179,13 @@ class GoogleMapViewController { /// If maximum zoom preference is not set previously, returns maximum possible /// zoom level for the current map type. Future getMaxZoomPreference() { - return GoogleMapsNavigationPlatform.instance + return GoogleMapsNavigationPlatform.instance.viewAPI .getMaxZoomPreference(viewId: _viewId); } /// Removes any previously specified upper and lower zoom bounds. Future resetMinMaxZoomPreference() { - return GoogleMapsNavigationPlatform.instance + return GoogleMapsNavigationPlatform.instance.viewAPI .resetMinMaxZoomPreference(viewId: _viewId); } @@ -195,7 +198,7 @@ class GoogleMapViewController { /// Throws [MinZoomRangeException] if [minZoomPreference] is /// greater than maximum zoom lavel. Future setMinZoomPreference(double minZoomPreference) { - return GoogleMapsNavigationPlatform.instance.setMinZoomPreference( + return GoogleMapsNavigationPlatform.instance.viewAPI.setMinZoomPreference( viewId: _viewId, minZoomPreference: minZoomPreference); } @@ -210,18 +213,19 @@ class GoogleMapViewController { /// Throws [MaxZoomRangeException] if [maxZoomPreference] is /// less than minimum zoom lavel. Future setMaxZoomPreference(double maxZoomPreference) { - return GoogleMapsNavigationPlatform.instance.setMaxZoomPreference( + return GoogleMapsNavigationPlatform.instance.viewAPI.setMaxZoomPreference( viewId: _viewId, maxZoomPreference: maxZoomPreference); } /// Retrieves all markers that have been added to the map view. Future> getMarkers() { - return GoogleMapsNavigationPlatform.instance.getMarkers(viewId: _viewId); + return GoogleMapsNavigationPlatform.instance.viewAPI + .getMarkers(viewId: _viewId); } /// Add markers to the map view. Future> addMarkers(List markerOptions) { - return GoogleMapsNavigationPlatform.instance + return GoogleMapsNavigationPlatform.instance.viewAPI .addMarkers(viewId: _viewId, markerOptions: markerOptions); } @@ -231,7 +235,7 @@ class GoogleMapViewController { /// more markers that have not been added to the map view via [addMarkers] or /// contains markers that have already been removed from the map view. Future> updateMarkers(List markers) async { - return GoogleMapsNavigationPlatform.instance + return GoogleMapsNavigationPlatform.instance.viewAPI .updateMarkers(viewId: _viewId, markers: markers); } @@ -241,23 +245,25 @@ class GoogleMapViewController { /// more markers that have not been added to the map view via [addMarkers] or /// contains markers that have already been removed from the map view. Future removeMarkers(List markers) async { - return GoogleMapsNavigationPlatform.instance + return GoogleMapsNavigationPlatform.instance.viewAPI .removeMarkers(viewId: _viewId, markers: markers); } /// Remove all markers from the map view. Future clearMarkers() { - return GoogleMapsNavigationPlatform.instance.clearMarkers(viewId: _viewId); + return GoogleMapsNavigationPlatform.instance.viewAPI + .clearMarkers(viewId: _viewId); } /// Retrieves all polygons that have been added to the map view. Future> getPolygons() { - return GoogleMapsNavigationPlatform.instance.getPolygons(viewId: _viewId); + return GoogleMapsNavigationPlatform.instance.viewAPI + .getPolygons(viewId: _viewId); } /// Add polygons to the map view. Future> addPolygons(List polygonOptions) { - return GoogleMapsNavigationPlatform.instance + return GoogleMapsNavigationPlatform.instance.viewAPI .addPolygons(viewId: _viewId, polygonOptions: polygonOptions); } @@ -267,7 +273,7 @@ class GoogleMapViewController { /// polygon that has not beed added to the map view via [addPolygons] or /// contains polygon that has already been removed from the map view. Future> updatePolygons(List polygons) async { - return GoogleMapsNavigationPlatform.instance + return GoogleMapsNavigationPlatform.instance.viewAPI .updatePolygons(viewId: _viewId, polygons: polygons); } @@ -277,23 +283,25 @@ class GoogleMapViewController { /// polygon that has not beed added to the map view via [addPolygons] or /// contains polygon that has already been removed from the map view. Future removePolygons(List polygons) async { - return GoogleMapsNavigationPlatform.instance + return GoogleMapsNavigationPlatform.instance.viewAPI .removePolygons(viewId: _viewId, polygons: polygons); } /// Remove all polygons from the map view. Future clearPolygons() { - return GoogleMapsNavigationPlatform.instance.clearPolygons(viewId: _viewId); + return GoogleMapsNavigationPlatform.instance.viewAPI + .clearPolygons(viewId: _viewId); } /// Retrieves all polylines that have been added to the map view. Future> getPolylines() { - return GoogleMapsNavigationPlatform.instance.getPolylines(viewId: _viewId); + return GoogleMapsNavigationPlatform.instance.viewAPI + .getPolylines(viewId: _viewId); } /// Add polylines to the map view. Future> addPolylines(List polylineOptions) { - return GoogleMapsNavigationPlatform.instance + return GoogleMapsNavigationPlatform.instance.viewAPI .addPolylines(viewId: _viewId, polylineOptions: polylineOptions); } @@ -303,7 +311,7 @@ class GoogleMapViewController { /// polyline that has not beed added to the map view via [addPolylines] or /// contains polyline that has already been removed from the map view. Future> updatePolylines(List polylines) async { - return GoogleMapsNavigationPlatform.instance + return GoogleMapsNavigationPlatform.instance.viewAPI .updatePolylines(viewId: _viewId, polylines: polylines); } @@ -313,24 +321,25 @@ class GoogleMapViewController { /// polyline that has not beed added to the map view via [addPolylines] or /// contains polyline that has already been removed from the map view. Future removePolylines(List polylines) async { - return GoogleMapsNavigationPlatform.instance + return GoogleMapsNavigationPlatform.instance.viewAPI .removePolylines(viewId: _viewId, polylines: polylines); } /// Remove all polylines from the map view. Future clearPolylines() { - return GoogleMapsNavigationPlatform.instance + return GoogleMapsNavigationPlatform.instance.viewAPI .clearPolylines(viewId: _viewId); } /// Gets all circles from the map view. Future> getCircles() { - return GoogleMapsNavigationPlatform.instance.getCircles(viewId: _viewId); + return GoogleMapsNavigationPlatform.instance.viewAPI + .getCircles(viewId: _viewId); } /// Add circles to the map view. Future> addCircles(List options) { - return GoogleMapsNavigationPlatform.instance + return GoogleMapsNavigationPlatform.instance.viewAPI .addCircles(viewId: _viewId, options: options); } @@ -340,7 +349,7 @@ class GoogleMapViewController { /// more circles that have not been added to the map view via [addCircles] or /// contains circles that have already been removed from the map view. Future> updateCircles(List circles) async { - return GoogleMapsNavigationPlatform.instance + return GoogleMapsNavigationPlatform.instance.viewAPI .updateCircles(viewId: _viewId, circles: circles); } @@ -350,17 +359,18 @@ class GoogleMapViewController { /// more circles that have not been added to the map view via [addCircles] or /// contains circles that have already been removed from the map view. Future removeCircles(List circles) async { - return GoogleMapsNavigationPlatform.instance + return GoogleMapsNavigationPlatform.instance.viewAPI .removeCircles(viewId: _viewId, circles: circles); } /// Remove all circles from the map view. Future clearCircles() { - return GoogleMapsNavigationPlatform.instance.clearCircles(viewId: _viewId); + return GoogleMapsNavigationPlatform.instance.viewAPI + .clearCircles(viewId: _viewId); } /// Remove all markers, polylines, polygons, overlays, etc from the map view. Future clear() { - return GoogleMapsNavigationPlatform.instance.clear(viewId: _viewId); + return GoogleMapsNavigationPlatform.instance.viewAPI.clear(viewId: _viewId); } } diff --git a/lib/src/google_maps_navigation_view.dart b/lib/src/google_maps_navigation_view.dart index f68ac66..2552b2e 100644 --- a/lib/src/google_maps_navigation_view.dart +++ b/lib/src/google_maps_navigation_view.dart @@ -158,35 +158,35 @@ class GoogleMapsNavigationViewState void _initNavigationViewListeners(int viewId) { if (widget.onRecenterButtonClicked != null) { - GoogleMapsNavigationPlatform.instance + GoogleMapsNavigationPlatform.instance.viewAPI .getNavigationRecenterButtonClickedEventStream(viewId: viewId) .listen(widget.onRecenterButtonClicked); } if (widget.onMyLocationClicked != null) { - GoogleMapsNavigationPlatform.instance + GoogleMapsNavigationPlatform.instance.viewAPI .getMyLocationClickedEventStream(viewId: viewId) .listen(widget.onMyLocationClicked); } if (widget.onNavigationUIEnabledChanged != null) { - GoogleMapsNavigationPlatform.instance + GoogleMapsNavigationPlatform.instance.viewAPI .getNavigationUIEnabledChangedEventStream(viewId: viewId) .listen((NavigationUIEnabledChangedEvent event) { widget.onNavigationUIEnabledChanged?.call(event.navigationUIEnabled); }); } if (widget.onMyLocationButtonClicked != null) { - GoogleMapsNavigationPlatform.instance + GoogleMapsNavigationPlatform.instance.viewAPI .getMyLocationButtonClickedEventStream(viewId: viewId) .listen(widget.onMyLocationButtonClicked); } if (widget.onCameraMoveStarted != null || widget.onCameraMove != null || widget.onCameraIdle != null) { - GoogleMapsNavigationPlatform.instance + GoogleMapsNavigationPlatform.instance.viewAPI .registerOnCameraChangedListener(viewId: viewId); } - GoogleMapsNavigationPlatform.instance + GoogleMapsNavigationPlatform.instance.viewAPI .getCameraChangedEventStream(viewId: viewId) .listen((CameraChangedEvent event) { switch (event.eventType) { diff --git a/lib/src/google_maps_navigation_view_controller.dart b/lib/src/google_maps_navigation_view_controller.dart index 36c493f..231d3aa 100644 --- a/lib/src/google_maps_navigation_view_controller.dart +++ b/lib/src/google_maps_navigation_view_controller.dart @@ -26,7 +26,7 @@ class GoogleNavigationViewController extends GoogleMapViewController { /// Is the navigation trip progress bar enabled. Future isNavigationTripProgressBarEnabled() { - return GoogleMapsNavigationPlatform.instance + return GoogleMapsNavigationPlatform.instance.viewAPI .isNavigationTripProgressBarEnabled(viewId: getViewId()); } @@ -34,7 +34,7 @@ class GoogleNavigationViewController extends GoogleMapViewController { /// /// By default, the navigation trip progress bar is disabled. Future setNavigationTripProgressBarEnabled(bool enabled) { - return GoogleMapsNavigationPlatform.instance + return GoogleMapsNavigationPlatform.instance.viewAPI .setNavigationTripProgressBarEnabled( viewId: getViewId(), enabled: enabled, @@ -43,7 +43,7 @@ class GoogleNavigationViewController extends GoogleMapViewController { /// Is the navigation header enabled. Future isNavigationHeaderEnabled() { - return GoogleMapsNavigationPlatform.instance + return GoogleMapsNavigationPlatform.instance.viewAPI .isNavigationHeaderEnabled(viewId: getViewId()); } @@ -51,7 +51,8 @@ class GoogleNavigationViewController extends GoogleMapViewController { /// /// By default, the navigation header is enabled. Future setNavigationHeaderEnabled(bool enabled) { - return GoogleMapsNavigationPlatform.instance.setNavigationHeaderEnabled( + return GoogleMapsNavigationPlatform.instance.viewAPI + .setNavigationHeaderEnabled( viewId: getViewId(), enabled: enabled, ); @@ -59,7 +60,7 @@ class GoogleNavigationViewController extends GoogleMapViewController { /// Is the navigation footer enabled. Future isNavigationFooterEnabled() { - return GoogleMapsNavigationPlatform.instance + return GoogleMapsNavigationPlatform.instance.viewAPI .isNavigationFooterEnabled(viewId: getViewId()); } @@ -70,7 +71,8 @@ class GoogleNavigationViewController extends GoogleMapViewController { /// Also known as ETA card, for example in Android /// calls [setEtaCardEnabled().](https://developers.google.com/maps/documentation/navigation/android-sdk/v1/reference/com/google/android/libraries/navigation/NavigationView#setEtaCardEnabled(boolean)) Future setNavigationFooterEnabled(bool enabled) { - return GoogleMapsNavigationPlatform.instance.setNavigationFooterEnabled( + return GoogleMapsNavigationPlatform.instance.viewAPI + .setNavigationFooterEnabled( viewId: getViewId(), enabled: enabled, ); @@ -78,7 +80,7 @@ class GoogleNavigationViewController extends GoogleMapViewController { /// Can the speed limit indication be displayed. Future isSpeedLimitIconEnabled() { - return GoogleMapsNavigationPlatform.instance + return GoogleMapsNavigationPlatform.instance.viewAPI .isSpeedLimitIconEnabled(viewId: getViewId()); } @@ -86,7 +88,8 @@ class GoogleNavigationViewController extends GoogleMapViewController { /// /// By default, the speed limit is not displayed. Future setSpeedLimitIconEnabled(bool enabled) { - return GoogleMapsNavigationPlatform.instance.setSpeedLimitIconEnabled( + return GoogleMapsNavigationPlatform.instance.viewAPI + .setSpeedLimitIconEnabled( viewId: getViewId(), enabled: enabled, ); @@ -94,7 +97,7 @@ class GoogleNavigationViewController extends GoogleMapViewController { /// Can the speedometer be displayed. Future isSpeedometerEnabled() { - return GoogleMapsNavigationPlatform.instance + return GoogleMapsNavigationPlatform.instance.viewAPI .isSpeedometerEnabled(viewId: getViewId()); } @@ -102,7 +105,7 @@ class GoogleNavigationViewController extends GoogleMapViewController { /// /// By default, the speedometer is not displayed. Future setSpeedometerEnabled(bool enabled) { - return GoogleMapsNavigationPlatform.instance.setSpeedometerEnabled( + return GoogleMapsNavigationPlatform.instance.viewAPI.setSpeedometerEnabled( viewId: getViewId(), enabled: enabled, ); @@ -110,7 +113,7 @@ class GoogleNavigationViewController extends GoogleMapViewController { /// Are the incident cards displayed. Future isTrafficIncidentCardsEnabled() { - return GoogleMapsNavigationPlatform.instance + return GoogleMapsNavigationPlatform.instance.viewAPI .isTrafficIncidentCardsEnabled(viewId: getViewId()); } @@ -118,7 +121,8 @@ class GoogleNavigationViewController extends GoogleMapViewController { /// /// By default, the incident cards are shown. Future setTrafficIncidentCardsEnabled(bool enabled) { - return GoogleMapsNavigationPlatform.instance.setTrafficIncidentCardsEnabled( + return GoogleMapsNavigationPlatform.instance.viewAPI + .setTrafficIncidentCardsEnabled( viewId: getViewId(), enabled: enabled, ); @@ -126,7 +130,7 @@ class GoogleNavigationViewController extends GoogleMapViewController { /// Check if the navigation user interface is shown. Future isNavigationUIEnabled() { - return GoogleMapsNavigationPlatform.instance + return GoogleMapsNavigationPlatform.instance.viewAPI .isNavigationUIEnabled(viewId: getViewId()); } @@ -142,7 +146,7 @@ class GoogleNavigationViewController extends GoogleMapViewController { /// Fails on Android if the navigation session has not been initialized, /// and on iOS if the terms and conditions have not been accepted. Future setNavigationUIEnabled(bool enabled) { - return GoogleMapsNavigationPlatform.instance.setNavigationUIEnabled( + return GoogleMapsNavigationPlatform.instance.viewAPI.setNavigationUIEnabled( viewId: getViewId(), enabled: enabled, ); @@ -152,7 +156,7 @@ class GoogleNavigationViewController extends GoogleMapViewController { /// /// See also [followMyLocation] and [animateCamera]. Future showRouteOverview() { - return GoogleMapsNavigationPlatform.instance.showRouteOverview( + return GoogleMapsNavigationPlatform.instance.viewAPI.showRouteOverview( viewId: getViewId(), ); } diff --git a/lib/src/google_navigation_flutter.dart b/lib/src/google_navigation_flutter.dart index 83369d0..9ce0093 100644 --- a/lib/src/google_navigation_flutter.dart +++ b/lib/src/google_navigation_flutter.dart @@ -168,7 +168,7 @@ class NavigationViewUISettings { /// By default, the my location button is visible /// when the my location indicator is shown. Future setMyLocationButtonEnabled(bool enabled) { - return GoogleMapsNavigationPlatform.instance + return GoogleMapsNavigationPlatform.instance.viewAPI .setMyLocationButtonEnabled(viewId: _viewId, enabled: enabled); } @@ -181,7 +181,7 @@ class NavigationViewUISettings { /// Note: By default, the button click events are not consumed, and the map /// follows its native default behavior. This method can be used to override this behavior. Future setConsumeMyLocationButtonClickEventsEnabled(bool enabled) { - return GoogleMapsNavigationPlatform.instance + return GoogleMapsNavigationPlatform.instance.viewAPI .setConsumeMyLocationButtonClickEventsEnabled( viewId: _viewId, enabled: enabled); } @@ -190,7 +190,7 @@ class NavigationViewUISettings { /// /// Initial value can be set with [GoogleMapsNavigationView.initialZoomGesturesEnabled]. Future setZoomGesturesEnabled(bool enabled) { - return GoogleMapsNavigationPlatform.instance + return GoogleMapsNavigationPlatform.instance.viewAPI .setZoomGesturesEnabled(viewId: _viewId, enabled: enabled); } @@ -200,7 +200,7 @@ class NavigationViewUISettings { /// /// The zoom controls are only available on Android. Throws [UnsupportedError] on iOS. Future setZoomControlsEnabled(bool enabled) { - return GoogleMapsNavigationPlatform.instance + return GoogleMapsNavigationPlatform.instance.viewAPI .setZoomControlsEnabled(viewId: _viewId, enabled: enabled); } @@ -211,7 +211,7 @@ class NavigationViewUISettings { /// /// Initial value can be set with [GoogleMapsNavigationView.initialCompassEnabled]. Future setCompassEnabled(bool enabled) { - return GoogleMapsNavigationPlatform.instance + return GoogleMapsNavigationPlatform.instance.viewAPI .setCompassEnabled(viewId: _viewId, enabled: enabled); } @@ -219,7 +219,7 @@ class NavigationViewUISettings { /// /// Initial value can be set with [GoogleMapsNavigationView.initialRotateGesturesEnabled]. Future setRotateGesturesEnabled(bool enabled) { - return GoogleMapsNavigationPlatform.instance + return GoogleMapsNavigationPlatform.instance.viewAPI .setRotateGesturesEnabled(viewId: _viewId, enabled: enabled); } @@ -227,7 +227,7 @@ class NavigationViewUISettings { /// /// Initial value can be set with [GoogleMapsNavigationView.initialScrollGesturesEnabled]. Future setScrollGesturesEnabled(bool enabled) { - return GoogleMapsNavigationPlatform.instance + return GoogleMapsNavigationPlatform.instance.viewAPI .setScrollGesturesEnabled(viewId: _viewId, enabled: enabled); } @@ -236,7 +236,7 @@ class NavigationViewUISettings { /// /// Initial value can be set with [GoogleMapsNavigationView.initialScrollGesturesEnabledDuringRotateOrZoom]. Future setScrollGesturesDuringRotateOrZoomEnabled(bool enabled) { - return GoogleMapsNavigationPlatform.instance + return GoogleMapsNavigationPlatform.instance.viewAPI .setScrollGesturesDuringRotateOrZoomEnabled( viewId: _viewId, enabled: enabled); } @@ -245,7 +245,7 @@ class NavigationViewUISettings { /// /// Initial value can be set with [GoogleMapsNavigationView.initialTiltGesturesEnabled]. Future setTiltGesturesEnabled(bool enabled) { - return GoogleMapsNavigationPlatform.instance + return GoogleMapsNavigationPlatform.instance.viewAPI .setTiltGesturesEnabled(viewId: _viewId, enabled: enabled); } @@ -253,7 +253,7 @@ class NavigationViewUISettings { /// /// By default, the traffic layer is off. Future setTrafficEnabled(bool enabled) { - return GoogleMapsNavigationPlatform.instance + return GoogleMapsNavigationPlatform.instance.viewAPI .setTrafficEnabled(viewId: _viewId, enabled: enabled); } @@ -263,25 +263,25 @@ class NavigationViewUISettings { /// /// The map toolbar is only available on Android. Throws [UnsupportedError] on iOS. Future setMapToolbarEnabled(bool enabled) { - return GoogleMapsNavigationPlatform.instance + return GoogleMapsNavigationPlatform.instance.viewAPI .setMapToolbarEnabled(viewId: _viewId, enabled: enabled); } /// Checks if the my location button is enabled. Future isMyLocationButtonEnabled() async { - return GoogleMapsNavigationPlatform.instance + return GoogleMapsNavigationPlatform.instance.viewAPI .isMyLocationButtonEnabled(viewId: _viewId); } /// Checks if the my location button consumes click events. Future isConsumeMyLocationButtonClickEventsEnabled() async { - return GoogleMapsNavigationPlatform.instance + return GoogleMapsNavigationPlatform.instance.viewAPI .isConsumeMyLocationButtonClickEventsEnabled(viewId: _viewId); } /// Checks if the zoom gestures are enabled. Future isZoomGesturesEnabled() async { - return GoogleMapsNavigationPlatform.instance + return GoogleMapsNavigationPlatform.instance.viewAPI .isZoomGesturesEnabled(viewId: _viewId); } @@ -289,38 +289,38 @@ class NavigationViewUISettings { /// /// The zoom controls are only available on Android. Throws [UnsupportedError] on iOS. Future isZoomControlsEnabled() async { - return GoogleMapsNavigationPlatform.instance + return GoogleMapsNavigationPlatform.instance.viewAPI .isZoomControlsEnabled(viewId: _viewId); } /// Checks if the compass is enabled. Future isCompassEnabled() async { - return GoogleMapsNavigationPlatform.instance + return GoogleMapsNavigationPlatform.instance.viewAPI .isCompassEnabled(viewId: _viewId); } /// Checks if the rotate gestures are enabled. Future isRotateGesturesEnabled() async { - return GoogleMapsNavigationPlatform.instance + return GoogleMapsNavigationPlatform.instance.viewAPI .isRotateGesturesEnabled(viewId: _viewId); } /// Checks if the scroll gestures are enabled. Future isScrollGesturesEnabled() async { - return GoogleMapsNavigationPlatform.instance + return GoogleMapsNavigationPlatform.instance.viewAPI .isScrollGesturesEnabled(viewId: _viewId); } /// Checks if the scroll gestures are enabled during the rotation and /// zoom gestures. Future isScrollGesturesEnabledDuringRotateOrZoom() async { - return GoogleMapsNavigationPlatform.instance + return GoogleMapsNavigationPlatform.instance.viewAPI .isScrollGesturesEnabledDuringRotateOrZoom(viewId: _viewId); } /// Checks if the scroll gestures are enabled. Future isTiltGesturesEnabled() async { - return GoogleMapsNavigationPlatform.instance + return GoogleMapsNavigationPlatform.instance.viewAPI .isTiltGesturesEnabled(viewId: _viewId); } @@ -328,13 +328,13 @@ class NavigationViewUISettings { /// /// The map toolbar is only available on Android. Throws [UnsupportedError] on iOS. Future isMapToolbarEnabled() async { - return GoogleMapsNavigationPlatform.instance + return GoogleMapsNavigationPlatform.instance.viewAPI .isMapToolbarEnabled(viewId: _viewId); } /// Checks if the map is displaying traffic data. Future isTrafficEnabled() async { - return GoogleMapsNavigationPlatform.instance + return GoogleMapsNavigationPlatform.instance.viewAPI .isTrafficEnabled(viewId: _viewId); } } diff --git a/lib/src/google_navigation_flutter_android.dart b/lib/src/google_navigation_flutter_android.dart index d2998b0..7bda934 100644 --- a/lib/src/google_navigation_flutter_android.dart +++ b/lib/src/google_navigation_flutter_android.dart @@ -15,7 +15,6 @@ import 'package:flutter/rendering.dart'; import 'package:flutter/services.dart'; import 'package:flutter/widgets.dart'; -import 'package:google_navigation_flutter/src/method_channel/common_auto_view_api.dart'; import '../google_navigation_flutter.dart'; import 'google_navigation_flutter_platform_interface.dart'; @@ -25,15 +24,28 @@ import 'method_channel/method_channel.dart'; /// Google Maps Navigation Platform Android specific functionalities. /// @nodoc -class GoogleMapsNavigationAndroid extends GoogleMapsNavigationPlatform - with - CommonNavigationSessionAPI, - CommonMapViewAPI, - CommonAutoMapViewAPI, - CommonImageRegistryAPI { +class GoogleMapsNavigationAndroid extends GoogleMapsNavigationPlatform { + /// Creates a GoogleMapsNavigationAndroid. + GoogleMapsNavigationAndroid( + AndroidNavigationSessionAPIImpl navigationSessionAPI, + MapViewAPIImpl viewAPI, + AutoMapViewAPIImpl autoAPI, + ImageRegistryAPIImpl imageRegistryAPI, + ) : super( + navigationSessionAPI, + viewAPI, + imageRegistryAPI, + autoAPI, + ); + /// Registers the Android implementation of GoogleMapsNavigationPlatform. static void registerWith() { - GoogleMapsNavigationPlatform.instance = GoogleMapsNavigationAndroid(); + GoogleMapsNavigationPlatform.instance = GoogleMapsNavigationAndroid( + AndroidNavigationSessionAPIImpl(), + MapViewAPIImpl(), + AutoMapViewAPIImpl(), + ImageRegistryAPIImpl(), + ); } @override @@ -61,14 +73,17 @@ class GoogleMapsNavigationAndroid extends GoogleMapsNavigationPlatform required MapViewInitializationOptions initializationOptions, required MapReadyCallback onMapReady}) { // Initialize method channel for view communication if needed. - ensureViewAPISetUp(); + viewAPI.ensureViewAPISetUp(); // This is used in the platform side to register the platform view. const String viewType = 'google_navigation_flutter'; // Build creation params used to initialize navigation view with initial parameters final ViewCreationOptionsDto creationParams = - buildNavigationViewCreationOptions(mapViewType, initializationOptions); + viewAPI.buildNavigationViewCreationOptions( + mapViewType, + initializationOptions, + ); return PlatformViewLink( viewType: viewType, @@ -96,7 +111,7 @@ class GoogleMapsNavigationAndroid extends GoogleMapsNavigationPlatform (int viewId) async { // On Android the map is initialized asyncronously. // Wait map to be ready before calling [onMapReady] callback - await awaitMapReady(viewId: viewId); + await viewAPI.awaitMapReady(viewId: viewId); onMapReady(viewId); }, ) @@ -105,12 +120,6 @@ class GoogleMapsNavigationAndroid extends GoogleMapsNavigationPlatform ); } - @override - Future allowBackgroundLocationUpdates(bool allow) { - throw UnsupportedError( - 'allowBackgroundLocationUpdates(bool allow) is iOS only function and should not be called from Android.'); - } - @override @visibleForTesting void enableDebugInspection() { @@ -118,3 +127,11 @@ class GoogleMapsNavigationAndroid extends GoogleMapsNavigationPlatform GoogleNavigationInspectorAndroid(); } } + +class AndroidNavigationSessionAPIImpl extends NavigationSessionAPIImpl { + @override + Future allowBackgroundLocationUpdates(bool allow) { + throw UnsupportedError( + 'allowBackgroundLocationUpdates(bool allow) is iOS only function and should not be called from Android.'); + } +} diff --git a/lib/src/google_navigation_flutter_ios.dart b/lib/src/google_navigation_flutter_ios.dart index 7630d97..17c3071 100644 --- a/lib/src/google_navigation_flutter_ios.dart +++ b/lib/src/google_navigation_flutter_ios.dart @@ -14,7 +14,6 @@ import 'package:flutter/services.dart'; import 'package:flutter/widgets.dart'; -import 'package:google_navigation_flutter/src/method_channel/common_auto_view_api.dart'; import '../google_navigation_flutter.dart'; import 'google_navigation_flutter_platform_interface.dart'; @@ -24,15 +23,28 @@ import 'method_channel/method_channel.dart'; /// Google Maps Navigation Platform iOS specific functionalities. /// @nodoc -class GoogleMapsNavigationIOS extends GoogleMapsNavigationPlatform - with - CommonNavigationSessionAPI, - CommonMapViewAPI, - CommonAutoMapViewAPI, - CommonImageRegistryAPI { +class GoogleMapsNavigationIOS extends GoogleMapsNavigationPlatform { + /// Creates a GoogleMapsNavigationIOS. + GoogleMapsNavigationIOS( + NavigationSessionAPIImpl navigationSessionAPI, + MapViewAPIImpl viewAPI, + AutoMapViewAPIImpl autoAPI, + ImageRegistryAPIImpl imageRegistryAPI, + ) : super( + navigationSessionAPI, + viewAPI, + imageRegistryAPI, + autoAPI, + ); + /// Registers the iOS implementation of GoogleMapsNavigationPlatform. static void registerWith() { - GoogleMapsNavigationPlatform.instance = GoogleMapsNavigationIOS(); + GoogleMapsNavigationPlatform.instance = GoogleMapsNavigationIOS( + NavigationSessionAPIImpl(), + MapViewAPIImpl(), + AutoMapViewAPIImpl(), + ImageRegistryAPIImpl(), + ); } @override @@ -60,14 +72,17 @@ class GoogleMapsNavigationIOS extends GoogleMapsNavigationPlatform required MapViewInitializationOptions initializationOptions, required MapReadyCallback onMapReady}) { // Initialize method channel for view communication if needed. - ensureViewAPISetUp(); + viewAPI.ensureViewAPISetUp(); // This is used in the platform side to register the platform view. const String viewType = 'google_navigation_flutter'; // Build creation params used to initialize navigation view with initial parameters final ViewCreationOptionsDto creationParams = - buildNavigationViewCreationOptions(mapViewType, initializationOptions); + viewAPI.buildNavigationViewCreationOptions( + mapViewType, + initializationOptions, + ); return UiKitView( viewType: viewType, @@ -75,7 +90,7 @@ class GoogleMapsNavigationIOS extends GoogleMapsNavigationPlatform creationParamsCodec: const StandardMessageCodec(), onPlatformViewCreated: (int viewId) async { // Wait map to be ready before calling [onMapReady] callback - await awaitMapReady(viewId: viewId); + await viewAPI.awaitMapReady(viewId: viewId); onMapReady(viewId); }, gestureRecognizers: initializationOptions.gestureRecognizers, diff --git a/lib/src/google_navigation_flutter_platform_interface.dart b/lib/src/google_navigation_flutter_platform_interface.dart index 288f3f6..df854e1 100644 --- a/lib/src/google_navigation_flutter_platform_interface.dart +++ b/lib/src/google_navigation_flutter_platform_interface.dart @@ -11,11 +11,9 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. - -import 'dart:async'; -import 'dart:typed_data'; - import 'package:flutter/widgets.dart'; + +import 'package:google_navigation_flutter/src/method_channel/method_channel.dart'; import 'package:plugin_platform_interface/plugin_platform_interface.dart'; import '../google_navigation_flutter.dart'; @@ -37,14 +35,14 @@ enum MapViewType { /// Google Maps Navigation Platform Interface for iOS and Android implementations. /// @nodoc -abstract class GoogleMapsNavigationPlatform extends PlatformInterface - with - NavigationSessionAPIInterface, - MapViewAPIInterface, - AutoMapViewAPIInterface, - ImageRegistryAPIInterface { +abstract class GoogleMapsNavigationPlatform extends PlatformInterface { /// Constructs a GoogleMapsNavigationPlatform. - GoogleMapsNavigationPlatform() : super(token: _token); + GoogleMapsNavigationPlatform( + this.navigationSessionAPI, + this.viewAPI, + this.imageRegistryAPI, + this.autoAPI, + ) : super(token: _token); static final Object _token = Object(); @@ -68,6 +66,11 @@ abstract class GoogleMapsNavigationPlatform extends PlatformInterface PlatformInterface.verifyToken(instance, _token); } + final NavigationSessionAPIImpl navigationSessionAPI; + final MapViewAPIImpl viewAPI; + final ImageRegistryAPIImpl imageRegistryAPI; + final AutoMapViewAPIImpl autoAPI; + /// Builds and returns a classic GoogleMaps map view. /// /// This method is responsible for creating a navigation view with the @@ -89,480 +92,6 @@ abstract class GoogleMapsNavigationPlatform extends PlatformInterface Widget buildNavigationView( {required MapViewInitializationOptions initializationOptions, required MapReadyCallback onMapReady}); -} - -/// API interface for actions of the navigation session. -abstract mixin class NavigationSessionAPIInterface { - /// Creates navigation session in the native platform and returns navigation session controller. - Future createNavigationSession( - bool abnormalTerminationReportingEnabled); - - /// Check whether navigator has been initialized. - Future isInitialized(); - - /// Cleanup navigation session. - Future cleanup(); - - /// Show terms and conditions dialog. - Future showTermsAndConditionsDialog(String title, String companyName, - bool shouldOnlyShowDriverAwarenessDisclaimer); - - /// Check if terms of service has been accepted. - Future areTermsAccepted(); - - /// Resets terms of service acceptance state. - Future resetTermsAccepted(); - - /// Gets the native navigation SDK version as string. - Future getNavSDKVersion(); - - /// Has guidance been started. - Future isGuidanceRunning(); - - /// Starts navigation guidance. - Future startGuidance(); - - /// Stops navigation guidance. - Future stopGuidance(); - - /// Sets destination waypoints and other settings. - Future setDestinations(Destinations destinations); - - /// Clears destinations. - Future clearDestinations(); - - /// Continues to next waypoint. - Future continueToNextDestination(); - - /// Gets current time and distance left. - Future getCurrentTimeAndDistance(); - - /// Sets audio guidance settings. - Future setAudioGuidance(NavigationAudioGuidanceSettings settings); - - /// Sets user location. - Future setUserLocation(LatLng location); - - /// Unsets user location. - Future removeUserLocation(); - - /// Simulates locations along existing route. - Future simulateLocationsAlongExistingRoute(); - - /// Simulates locations along existing route with simulation options. - Future simulateLocationsAlongExistingRouteWithOptions( - SimulationOptions options, - ); - - /// Simulates locations along new route. - Future simulateLocationsAlongNewRoute( - List waypoints, - ); - - /// Simulates locations along new route with routing options. - Future - simulateLocationsAlongNewRouteWithRoutingOptions( - List waypoints, - RoutingOptions routingOptions, - ); - - /// Simulates locations along new route with routing and simulation options. - Future - simulateLocationsAlongNewRouteWithRoutingAndSimulationOptions( - List waypoints, - RoutingOptions routingOptions, - SimulationOptions simulationOptions, - ); - - /// Pauses simulation. - Future pauseSimulation(); - - /// Resumes simulation. - Future resumeSimulation(); - - /// Sets state of allow background location updates. (iOS only) - Future allowBackgroundLocationUpdates(bool allow); - - /// Enables road snapped location updates. - Future enableRoadSnappedLocationUpdates(); - - /// Disables road snapped location updates. - Future disableRoadSnappedLocationUpdates(); - - /// Enables navigation info updates. - Future enableTurnByTurnNavigationEvents(int? numNextStepsToPreview); - - /// Disables navigation info updates. - Future disableTurnByTurnNavigationEvents(); - - /// Get route segments. - Future> getRouteSegments(); - - /// Get traveled route. - Future> getTraveledRoute(); - - /// Get current route segment. - Future getCurrentRouteSegment(); - - /// Get navigation speeding event stream from the navigation session. - Stream getNavigationSpeedingEventStream(); - - /// Get navigation road snapped location event stream from the navigation session. - Stream - getNavigationRoadSnappedLocationEventStream(); - - /// Get navigation road snapped raw location event stream from the navigation session. - /// Android only. - Stream - getNavigationRoadSnappedRawLocationEventStream(); - - /// Get navigation on arrival event stream from the navigation session. - Stream getNavigationOnArrivalEventStream(); - - /// Get navigation on rerouting event stream from the navigation session. - Stream getNavigationOnReroutingEventStream(); - - /// Get navigation on GPS availability update event stream from the navigation session. - Stream - getNavigationOnGpsAvailabilityUpdateEventStream(); - - /// Get navigation traffic updated event stream from the navigation session. - Stream getNavigationTrafficUpdatedEventStream(); - - /// Get navigation on route changed event stream from the navigation session. - Stream getNavigationOnRouteChangedEventStream(); - - /// Get navigation remaining time or distance event stream from the navigation session. - Stream - getNavigationRemainingTimeOrDistanceChangedEventStream(); - - /// Register remaining time or distance change listener with thresholds. - Future registerRemainingTimeOrDistanceChangedListener( - int remainingTimeThresholdSeconds, int remainingDistanceThresholdMeters); - - /// Get navigation info event stream from the navigation session. - Stream getNavInfoStream(); -} - -/// API interface for actions of the navigation view. -/// @nodoc -abstract mixin class MapViewAPIInterface { - /// Awaits the platform view to be ready for communication. - Future awaitMapReady({required int viewId}); - - /// Get the preference for whether the my location should be enabled or disabled. - Future isMyLocationEnabled({required int viewId}); - - /// Enabled location in the navigation view. - Future setMyLocationEnabled( - {required int viewId, required bool enabled}); - - /// Get the map type. - Future getMapType({required int viewId}); - - /// Modified visible map type. - Future setMapType({required int viewId, required MapType mapType}); - - /// Set map style by json string. - Future setMapStyle(int viewId, String? styleJson); - - /// Enables or disables the my-location button. - Future setMyLocationButtonEnabled( - {required int viewId, required bool enabled}); - - /// Enables or disables if the my location button consumes click events. - Future setConsumeMyLocationButtonClickEventsEnabled( - {required int viewId, required bool enabled}); - - /// Enables or disables the zoom gestures. - Future setZoomGesturesEnabled( - {required int viewId, required bool enabled}); - - /// Enables or disables the zoom controls. - Future setZoomControlsEnabled( - {required int viewId, required bool enabled}); - - /// Enables or disables the compass. - Future setCompassEnabled({required int viewId, required bool enabled}); - - /// Sets the preference for whether rotate gestures should be enabled or disabled. - Future setRotateGesturesEnabled( - {required int viewId, required bool enabled}); - - /// Sets the preference for whether scroll gestures should be enabled or disabled. - Future setScrollGesturesEnabled( - {required int viewId, required bool enabled}); - - /// Sets the preference for whether scroll gestures can take place at the same time as a zoom or rotate gesture. - Future setScrollGesturesDuringRotateOrZoomEnabled( - {required int viewId, required bool enabled}); - - /// Sets the preference for whether tilt gestures should be enabled or disabled. - Future setTiltGesturesEnabled( - {required int viewId, required bool enabled}); - - /// Sets the preference for whether the Map Toolbar should be enabled or disabled. - Future setMapToolbarEnabled( - {required int viewId, required bool enabled}); - - /// Turns the traffic layer on or off. - Future setTrafficEnabled({required int viewId, required bool enabled}); - - /// Get the preference for whether the my location button should be enabled or disabled. - Future isMyLocationButtonEnabled({required int viewId}); - - /// Get the preference for whether the my location button consumes click events. - Future isConsumeMyLocationButtonClickEventsEnabled( - {required int viewId}); - - /// Gets the preference for whether zoom gestures should be enabled or disabled. - Future isZoomGesturesEnabled({required int viewId}); - - /// Gets the preference for whether zoom controls should be enabled or disabled. - Future isZoomControlsEnabled({required int viewId}); - - /// Gets the preference for whether compass should be enabled or disabled. - Future isCompassEnabled({required int viewId}); - - /// Gets the preference for whether rotate gestures should be enabled or disabled. - Future isRotateGesturesEnabled({required int viewId}); - - /// Gets the preference for whether scroll gestures should be enabled or disabled. - Future isScrollGesturesEnabled({required int viewId}); - - /// Gets the preference for whether scroll gestures can take place at the same time as a zoom or rotate gesture. - Future isScrollGesturesEnabledDuringRotateOrZoom({required int viewId}); - - /// Gets the preference for whether tilt gestures should be enabled or disabled. - Future isTiltGesturesEnabled({required int viewId}); - - /// Gets whether the Map Toolbar is enabled/disabled. - Future isMapToolbarEnabled({required int viewId}); - - /// Checks whether the map is drawing traffic data. - Future isTrafficEnabled({required int viewId}); - - /// Sets the Camera to follow the location of the user. - Future followMyLocation( - {required int viewId, - required CameraPerspective perspective, - required double? zoomLevel}); - - /// Gets users current location. - Future getMyLocation({required int viewId}); - - /// Gets the current position of the camera. - Future getCameraPosition({required int viewId}); - - /// Gets the current visible area / camera bounds. - Future getVisibleRegion({required int viewId}); - - /// Animates the movement of the camera. - Future animateCamera( - {required int viewId, - required CameraUpdate cameraUpdate, - required int? duration, - AnimationFinishedCallback? onFinished}); - - /// Moves the camera. - Future moveCamera( - {required int viewId, required CameraUpdate cameraUpdate}); - - /// Is the navigation trip progress bar enabled. - Future isNavigationTripProgressBarEnabled({required int viewId}); - - /// Enable navigation trip progress bar. - Future setNavigationTripProgressBarEnabled( - {required int viewId, required bool enabled}); - - /// Is the navigation header enabled. - Future isNavigationHeaderEnabled({required int viewId}); - - /// Enable navigation header. - Future setNavigationHeaderEnabled( - {required int viewId, required bool enabled}); - - /// Is the navigation footer enabled. - Future isNavigationFooterEnabled({required int viewId}); - - /// Enable the navigation footer. - Future setNavigationFooterEnabled( - {required int viewId, required bool enabled}); - - /// Is the recenter button enabled. - Future isRecenterButtonEnabled({required int viewId}); - - /// Enable the recenter button. - Future setRecenterButtonEnabled( - {required int viewId, required bool enabled}); - - /// Is the speed limit displayed. - Future isSpeedLimitIconEnabled({required int viewId}); - - /// Should display speed limit. - Future setSpeedLimitIconEnabled( - {required int viewId, required bool enabled}); - - /// Is speedometer displayed. - Future isSpeedometerEnabled({required int viewId}); - - /// Should display speedometer. - Future setSpeedometerEnabled( - {required int viewId, required bool enabled}); - - /// Is incident cards displayed. - Future isTrafficIncidentCardsEnabled({required int viewId}); - - /// Should display incident cards. - Future setTrafficIncidentCardsEnabled( - {required int viewId, required bool enabled}); - - /// Is navigation UI enabled. - Future isNavigationUIEnabled({required int viewId}); - - /// Enable navigation UI. - Future setNavigationUIEnabled( - {required int viewId, required bool enabled}); - - /// Show route overview. - Future showRouteOverview({required int viewId}); - - /// Returns the minimum zoom level. - Future getMinZoomPreference({required int viewId}); - - /// Returns the maximum zoom level for the current camera position. - Future getMaxZoomPreference({required int viewId}); - - /// Removes any previously specified upper and lower zoom bounds. - Future resetMinMaxZoomPreference({required int viewId}); - - /// Sets a preferred lower bound for the camera zoom. - Future setMinZoomPreference( - {required int viewId, required double minZoomPreference}); - - /// Sets a preferred upper bound for the camera zoom. - Future setMaxZoomPreference( - {required int viewId, required double maxZoomPreference}); - - /// Get map clicked event stream from the navigation view. - Stream getMapClickEventStream({required int viewId}); - - /// Get map long clicked event stream from the navigation view. - Stream getMapLongClickEventStream({required int viewId}); - - /// Get navigation recenter button clicked event stream from the navigation view. - Stream - getNavigationRecenterButtonClickedEventStream({required int viewId}); - - /// Get all markers from map view. - Future> getMarkers({required int viewId}); - - /// Add markers to map view. - Future> addMarkers( - {required int viewId, required List markerOptions}); - - /// Update markers on the map view. - Future> updateMarkers( - {required int viewId, required List markers}); - - /// Remove markers from map view. - Future removeMarkers( - {required int viewId, required List markers}); - - /// Remove all markers from map view. - Future clearMarkers({required int viewId}); - - /// Removes all markers, polylines, polygons, overlays, etc from the map. - Future clear({required int viewId}); - - /// Get all polygons from map view. - Future> getPolygons({required int viewId}); - - /// Add polygons to map view. - Future> addPolygons( - {required int viewId, required List polygonOptions}); - - /// Update polygons on the map view. - Future> updatePolygons( - {required int viewId, required List polygons}); - - /// Remove polygons from map view. - Future removePolygons( - {required int viewId, required List polygons}); - - /// Remove all polygons from map view. - Future clearPolygons({required int viewId}); - - /// Get all polylines from map view. - Future> getPolylines({required int viewId}); - - /// Add polylines to map view. - Future> addPolylines( - {required int viewId, required List polylineOptions}); - - /// Update polylines on the map view. - Future> updatePolylines( - {required int viewId, required List polylines}); - - /// Remove polylines from map view. - Future removePolylines( - {required int viewId, required List polylines}); - - /// Remove all polylines from map view. - Future clearPolylines({required int viewId}); - - /// Get all circles from map view. - Future> getCircles({required int viewId}); - - /// Add circles to map view. - Future> addCircles( - {required int viewId, required List options}); - - /// Update circles on the map view. - Future> updateCircles( - {required int viewId, required List circles}); - - /// Remove circles from map view. - Future removeCircles( - {required int viewId, required List circles}); - - /// Remove all circles from map view. - Future clearCircles({required int viewId}); - - /// Register camera changed listeners. - Future registerOnCameraChangedListener({required int viewId}); - - /// Get navigation view marker event stream from the navigation view. - Stream getMarkerEventStream({required int viewId}); - - /// Get navigation view marker drag event stream from the navigation view. - Stream getMarkerDragEventStream({required int viewId}); - - /// Get navigation view polygon clicked event stream from the navigation view. - Stream getPolygonClickedEventStream( - {required int viewId}); - - /// Get navigation view polyline clicked event stream from the navigation view. - Stream getPolylineClickedEventStream( - {required int viewId}); - - /// Get navigation view circle clicked event stream from the navigation view. - Stream getCircleClickedEventStream({required int viewId}); - - /// Get navigation UI changed event stream from the navigation view. - Stream - getNavigationUIEnabledChangedEventStream({required int viewId}); - - /// Get navigation view my location clicked event stream from the navigation view. - Stream getMyLocationClickedEventStream( - {required int viewId}); - - /// Get navigation view my location button clicked event stream from the navigation view. - Stream getMyLocationButtonClickedEventStream( - {required int viewId}); - - /// Get navigation view camera changed event stream from the navigation view. - Stream getCameraChangedEventStream({required int viewId}); /// Populates [GoogleNavigationInspectorPlatform.instance] to allow /// inspecting the platform map state. @@ -572,229 +101,3 @@ abstract mixin class MapViewAPIInterface { 'enableDebugInspection() has not been implemented.'); } } - -abstract mixin class AutoMapViewAPIInterface { - /// Get the preference for whether the my location should be enabled or disabled. - Future isMyLocationEnabledForAuto(); - - /// Enabled location in the auto map view. - Future setMyLocationEnabledForAuto({required bool enabled}); - - /// Get the map type. - Future getMapTypeForAuto(); - - /// Modified visible map type. - Future setMapTypeForAuto({required MapType mapType}); - - /// Set map style by json string. - Future setMapStyleForAuto(String? styleJson); - - /// Enables or disables the my-location button. - Future setMyLocationButtonEnabledForAuto({required bool enabled}); - - /// Enables or disables if the my location button consumes click events. - Future setConsumeMyLocationButtonClickEventsEnabledForAuto( - {required bool enabled}); - - /// Enables or disables the zoom gestures. - Future setZoomGesturesEnabledForAuto({required bool enabled}); - - /// Enables or disables the zoom controls. - Future setZoomControlsEnabledForAuto({required bool enabled}); - - /// Enables or disables the compass. - Future setCompassEnabledForAuto({required bool enabled}); - - /// Sets the preference for whether rotate gestures should be enabled or disabled. - Future setRotateGesturesEnabledForAuto({required bool enabled}); - - /// Sets the preference for whether scroll gestures should be enabled or disabled. - Future setScrollGesturesEnabledForAuto({required bool enabled}); - - /// Sets the preference for whether scroll gestures can take place at the same time as a zoom or rotate gesture. - Future setScrollGesturesDuringRotateOrZoomEnabledForAuto( - {required bool enabled}); - - /// Sets the preference for whether tilt gestures should be enabled or disabled. - Future setTiltGesturesEnabledForAuto({required bool enabled}); - - /// Sets the preference for whether the Map Toolbar should be enabled or disabled. - Future setMapToolbarEnabledForAuto({required bool enabled}); - - /// Turns the traffic layer on or off. - Future setTrafficEnabledForAuto({required bool enabled}); - - /// Get the preference for whether the my location button should be enabled or disabled. - Future isMyLocationButtonEnabledForAuto(); - - /// Get the preference for whether the my location button consumes click events. - Future isConsumeMyLocationButtonClickEventsEnabledForAuto(); - - /// Gets the preference for whether zoom gestures should be enabled or disabled. - Future isZoomGesturesEnabledForAuto(); - - /// Gets the preference for whether zoom controls should be enabled or disabled. - Future isZoomControlsEnabledForAuto(); - - /// Gets the preference for whether compass should be enabled or disabled. - Future isCompassEnabledForAuto(); - - /// Gets the preference for whether rotate gestures should be enabled or disabled. - Future isRotateGesturesEnabledForAuto(); - - /// Gets the preference for whether scroll gestures should be enabled or disabled. - Future isScrollGesturesEnabledForAuto(); - - /// Gets the preference for whether scroll gestures can take place at the same time as a zoom or rotate gesture. - Future isScrollGesturesEnabledDuringRotateOrZoomForAuto(); - - /// Gets the preference for whether tilt gestures should be enabled or disabled. - Future isTiltGesturesEnabledForAuto(); - - /// Gets whether the Map Toolbar is enabled/disabled. - Future isMapToolbarEnabledForAuto(); - - /// Checks whether the map is drawing traffic data. - Future isTrafficEnabledForAuto(); - - /// Sets the Camera to follow the location of the user. - Future followMyLocationForAuto( - {required CameraPerspective perspective, required double? zoomLevel}); - - /// Gets users current location. - Future getMyLocationForAuto(); - - /// Gets the current position of the camera. - Future getCameraPositionForAuto(); - - /// Gets the current visible area / camera bounds. - Future getVisibleRegionForAuto(); - - /// Animates the movement of the camera. - Future animateCameraForAuto( - {required CameraUpdate cameraUpdate, - required int? duration, - AnimationFinishedCallback? onFinished}); - - /// Moves the camera. - Future moveCameraForAuto({required CameraUpdate cameraUpdate}); - - /// Returns the minimum zoom level. - Future getMinZoomPreferenceForAuto(); - - /// Returns the maximum zoom level for the current camera position. - Future getMaxZoomPreferenceForAuto(); - - /// Removes any previously specified upper and lower zoom bounds. - Future resetMinMaxZoomPreferenceForAuto(); - - /// Sets a preferred lower bound for the camera zoom. - Future setMinZoomPreferenceForAuto({required double minZoomPreference}); - - /// Sets a preferred upper bound for the camera zoom. - Future setMaxZoomPreferenceForAuto({required double maxZoomPreference}); - - /// Get all markers from auto map view. - Future> getMarkersForAuto(); - - /// Add markers to auto map view. - Future> addMarkersForAuto( - {required List markerOptions}); - - /// Update markers on the auto map view. - Future> updateMarkersForAuto({required List markers}); - - /// Remove markers from auto map view. - Future removeMarkersForAuto({required List markers}); - - /// Remove all markers from auto map view. - Future clearMarkersForAuto(); - - /// Removes all markers, polylines, polygons, overlays, etc from the map. - Future clearForAuto(); - - /// Get all polygons from map auto view. - Future> getPolygonsForAuto(); - - /// Add polygons to auto map view. - Future> addPolygonsForAuto( - {required List polygonOptions}); - - /// Update polygons on the auto map view. - Future> updatePolygonsForAuto( - {required List polygons}); - - /// Remove polygons from auto map view. - Future removePolygonsForAuto({required List polygons}); - - /// Remove all polygons from auto map view. - Future clearPolygonsForAuto(); - - /// Get all polylines from auto map view. - Future> getPolylinesForAuto(); - - /// Add polylines to auto map view. - Future> addPolylinesForAuto( - {required List polylineOptions}); - - /// Update polylines on the auto map view. - Future> updatePolylinesForAuto( - {required List polylines}); - - /// Remove polylines from auto map view. - Future removePolylinesForAuto({required List polylines}); - - /// Remove all polylines from auto map view. - Future clearPolylinesForAuto(); - - /// Get all circles from auto map view. - Future> getCirclesForAuto(); - - /// Add circles to auto map view. - Future> addCirclesForAuto( - {required List options}); - - /// Update circles on the auto map view. - Future> updateCirclesForAuto({required List circles}); - - /// Remove circles from auto map view. - Future removeCirclesForAuto({required List circles}); - - /// Remove all circles from auto map view. - Future clearCirclesForAuto(); - - /// Register camera changed listeners. - Future registerOnCameraChangedListenerForAuto(); - - // Check whether auto screen is available; - Future isAutoScreenAvailable(); - - /// Get custom navigation auto event stream from the auto view. - Stream getCustomNavigationAutoEventStream(); - - /// Get auto screen availibility changed event stream from the auto view. - Stream - getAutoScreenAvailabilityChangedEventStream(); - - void initializeAutoViewEventAPI(); -} - -/// API interface for actions of the image registry. -/// @nodoc -abstract mixin class ImageRegistryAPIInterface { - /// Register bitmap to image registry. - Future registerBitmapImage( - {required Uint8List bitmap, - required double imagePixelRatio, - double? width, - double? height}); - - /// Delete bitmap from image registry. - Future unregisterImage({required ImageDescriptor imageDescriptor}); - - /// Get all registered bitmaps from image registry. - Future> getRegisteredImages(); - - /// Remove all registered bitmaps from image registry. - Future clearRegisteredImages(); -} diff --git a/lib/src/method_channel/common_auto_view_api.dart b/lib/src/method_channel/auto_view_api.dart similarity index 75% rename from lib/src/method_channel/common_auto_view_api.dart rename to lib/src/method_channel/auto_view_api.dart index 88d70b1..c7c087a 100644 --- a/lib/src/method_channel/common_auto_view_api.dart +++ b/lib/src/method_channel/auto_view_api.dart @@ -18,12 +18,11 @@ import 'dart:io'; import 'package:flutter/services.dart'; import '../../google_navigation_flutter.dart'; -import '../google_navigation_flutter_platform_interface.dart'; import 'method_channel.dart'; /// @nodoc /// Class that handles map view and navigation view communications. -mixin CommonAutoMapViewAPI on AutoMapViewAPIInterface { +class AutoMapViewAPIImpl { final AutoMapViewApi _viewApi = AutoMapViewApi(); bool _viewApiHasBeenSetUp = false; final StreamController<_AutoEventWrapper> _autoEventStreamController = @@ -61,10 +60,16 @@ mixin CommonAutoMapViewAPI on AutoMapViewAPIInterface { return circleId; } + Stream _unwrapEventStream() { + // If event that does not + return _autoEventStreamController.stream + .where((_AutoEventWrapper wrapper) => (wrapper.event is T)) + .map((_AutoEventWrapper wrapper) => wrapper.event as T); + } + /// This function ensures that the event API has been setup. This should be /// called when initializing auto view controller. - @override - void initializeAutoViewEventAPI() { + void ensureAutoViewApiSetUp() { if (!_viewApiHasBeenSetUp) { AutoViewEventApi.setup( AutoViewEventApiImpl( @@ -74,29 +79,29 @@ mixin CommonAutoMapViewAPI on AutoMapViewAPIInterface { } } - @override - Future isMyLocationEnabledForAuto() { + /// Get the preference for whether the my location should be enabled or disabled. + Future isMyLocationEnabled() { return _viewApi.isMyLocationEnabled(); } - @override - Future setMyLocationEnabledForAuto({required bool enabled}) { + /// Enabled location in the navigation view. + Future setMyLocationEnabled({required bool enabled}) { return _viewApi.setMyLocationEnabled(enabled); } - @override - Future getMapTypeForAuto() async { + /// Get the map type. + Future getMapType() async { final MapTypeDto mapType = await _viewApi.getMapType(); return mapType.toMapType(); } - @override - Future setMapTypeForAuto({required MapType mapType}) async { + /// Modified visible map type. + Future setMapType({required MapType mapType}) async { return _viewApi.setMapType(mapType.toDto()); } - @override - Future setMapStyleForAuto(String? styleJson) async { + /// Set map style by json string. + Future setMapStyle(String? styleJson) async { try { // Set the given json to the viewApi or reset the map style if // the styleJson is null. @@ -110,24 +115,24 @@ mixin CommonAutoMapViewAPI on AutoMapViewAPIInterface { } } - @override - Future setMyLocationButtonEnabledForAuto({required bool enabled}) { + /// Enables or disables the my-location button. + Future setMyLocationButtonEnabled({required bool enabled}) { return _viewApi.setMyLocationButtonEnabled(enabled); } - @override - Future setConsumeMyLocationButtonClickEventsEnabledForAuto( + /// Enables or disables if the my location button consumes click events. + Future setConsumeMyLocationButtonClickEventsEnabled( {required bool enabled}) async { return _viewApi.setConsumeMyLocationButtonClickEventsEnabled(enabled); } - @override - Future setZoomGesturesEnabledForAuto({required bool enabled}) { + /// Enables or disables the zoom gestures. + Future setZoomGesturesEnabled({required bool enabled}) { return _viewApi.setZoomGesturesEnabled(enabled); } - @override - Future setZoomControlsEnabledForAuto({required bool enabled}) async { + /// Enables or disables the zoom controls. + Future setZoomControlsEnabled({required bool enabled}) async { try { return await _viewApi.setZoomControlsEnabled(enabled); } on PlatformException catch (error) { @@ -139,34 +144,34 @@ mixin CommonAutoMapViewAPI on AutoMapViewAPIInterface { } } - @override - Future setCompassEnabledForAuto({required bool enabled}) { + /// Enables or disables the compass. + Future setCompassEnabled({required bool enabled}) { return _viewApi.setCompassEnabled(enabled); } - @override - Future setRotateGesturesEnabledForAuto({required bool enabled}) { + /// Sets the preference for whether rotate gestures should be enabled or disabled. + Future setRotateGesturesEnabled({required bool enabled}) { return _viewApi.setRotateGesturesEnabled(enabled); } - @override - Future setScrollGesturesEnabledForAuto({required bool enabled}) { + /// Sets the preference for whether scroll gestures should be enabled or disabled. + Future setScrollGesturesEnabled({required bool enabled}) { return _viewApi.setScrollGesturesEnabled(enabled); } - @override - Future setScrollGesturesDuringRotateOrZoomEnabledForAuto( + /// Sets the preference for whether scroll gestures can take place at the same time as a zoom or rotate gesture. + Future setScrollGesturesDuringRotateOrZoomEnabled( {required bool enabled}) { return _viewApi.setScrollGesturesDuringRotateOrZoomEnabled(enabled); } - @override - Future setTiltGesturesEnabledForAuto({required bool enabled}) { + /// Sets the preference for whether tilt gestures should be enabled or disabled. + Future setTiltGesturesEnabled({required bool enabled}) { return _viewApi.setTiltGesturesEnabled(enabled); } - @override - Future setMapToolbarEnabledForAuto({required bool enabled}) async { + /// Sets the preference for whether the Map Toolbar should be enabled or disabled. + Future setMapToolbarEnabled({required bool enabled}) async { try { return await _viewApi.setMapToolbarEnabled(enabled); } on PlatformException catch (error) { @@ -178,28 +183,28 @@ mixin CommonAutoMapViewAPI on AutoMapViewAPIInterface { } } - @override - Future setTrafficEnabledForAuto({required bool enabled}) { + /// Turns the traffic layer on or off. + Future setTrafficEnabled({required bool enabled}) { return _viewApi.setTrafficEnabled(enabled); } - @override - Future isMyLocationButtonEnabledForAuto() { + /// Get the preference for whether the my location button should be enabled or disabled. + Future isMyLocationButtonEnabled() { return _viewApi.isMyLocationButtonEnabled(); } - @override - Future isConsumeMyLocationButtonClickEventsEnabledForAuto() { + /// Get the preference for whether the my location button consumes click events. + Future isConsumeMyLocationButtonClickEventsEnabled() { return _viewApi.isConsumeMyLocationButtonClickEventsEnabled(); } - @override - Future isZoomGesturesEnabledForAuto() { + /// Gets the preference for whether zoom gestures should be enabled or disabled. + Future isZoomGesturesEnabled() { return _viewApi.isZoomGesturesEnabled(); } - @override - Future isZoomControlsEnabledForAuto() async { + /// Gets the preference for whether zoom controls should be enabled or disabled. + Future isZoomControlsEnabled() async { try { return await _viewApi.isZoomControlsEnabled(); } on PlatformException catch (error) { @@ -211,33 +216,33 @@ mixin CommonAutoMapViewAPI on AutoMapViewAPIInterface { } } - @override - Future isCompassEnabledForAuto() { + /// Gets the preference for whether compass should be enabled or disabled. + Future isCompassEnabled() { return _viewApi.isCompassEnabled(); } - @override - Future isRotateGesturesEnabledForAuto() { + /// Gets the preference for whether rotate gestures should be enabled or disabled. + Future isRotateGesturesEnabled() { return _viewApi.isRotateGesturesEnabled(); } - @override - Future isScrollGesturesEnabledForAuto() { + /// Gets the preference for whether scroll gestures should be enabled or disabled. + Future isScrollGesturesEnabled() { return _viewApi.isScrollGesturesEnabled(); } - @override - Future isScrollGesturesEnabledDuringRotateOrZoomForAuto() { + /// Gets the preference for whether scroll gestures can take place at the same time as a zoom or rotate gesture. + Future isScrollGesturesEnabledDuringRotateOrZoom() { return _viewApi.isScrollGesturesEnabledDuringRotateOrZoom(); } - @override - Future isTiltGesturesEnabledForAuto() { + /// Gets the preference for whether tilt gestures should be enabled or disabled. + Future isTiltGesturesEnabled() { return _viewApi.isTiltGesturesEnabled(); } - @override - Future isMapToolbarEnabledForAuto() async { + /// Gets whether the Map Toolbar is enabled/disabled. + Future isMapToolbarEnabled() async { try { return await _viewApi.isMapToolbarEnabled(); } on PlatformException catch (error) { @@ -249,19 +254,19 @@ mixin CommonAutoMapViewAPI on AutoMapViewAPIInterface { } } - @override - Future isTrafficEnabledForAuto() { + /// Checks whether the map is drawing traffic data. + Future isTrafficEnabled() { return _viewApi.isTrafficEnabled(); } - @override - Future followMyLocationForAuto( + /// Sets the Camera to follow the location of the user. + Future followMyLocation( {required CameraPerspective perspective, required double? zoomLevel}) { return _viewApi.followMyLocation(perspective.toDto(), zoomLevel); } - @override - Future getMyLocationForAuto() async { + /// Gets users current location. + Future getMyLocation() async { final LatLngDto? myLocation = await _viewApi.getMyLocation(); if (myLocation == null) { return null; @@ -269,14 +274,14 @@ mixin CommonAutoMapViewAPI on AutoMapViewAPIInterface { return myLocation.toLatLng(); } - @override - Future getCameraPositionForAuto() async { + /// Gets the current position of the camera. + Future getCameraPosition() async { final CameraPositionDto position = await _viewApi.getCameraPosition(); return position.toCameraPosition(); } - @override - Future getVisibleRegionForAuto() async { + /// Gets the current visible area / camera bounds. + Future getVisibleRegion() async { final LatLngBoundsDto bounds = await _viewApi.getVisibleRegion(); return LatLngBounds( southwest: bounds.southwest.toLatLng(), @@ -284,8 +289,8 @@ mixin CommonAutoMapViewAPI on AutoMapViewAPIInterface { ); } - @override - Future animateCameraForAuto( + /// Animates the movement of the camera. + Future animateCamera( {required CameraUpdate cameraUpdate, required int? duration, AnimationFinishedCallback? onFinished}) async { @@ -340,8 +345,8 @@ mixin CommonAutoMapViewAPI on AutoMapViewAPIInterface { } } - @override - Future moveCameraForAuto({required CameraUpdate cameraUpdate}) async { + /// Moves the camera. + Future moveCamera({required CameraUpdate cameraUpdate}) async { switch (cameraUpdate.type) { case CameraUpdateType.cameraPosition: assert(cameraUpdate.cameraPosition != null, 'Camera position is null'); @@ -367,24 +372,23 @@ mixin CommonAutoMapViewAPI on AutoMapViewAPIInterface { } } - @override - Future getMinZoomPreferenceForAuto() { + /// Returns the minimum zoom level. + Future getMinZoomPreference() { return _viewApi.getMinZoomPreference(); } - @override - Future getMaxZoomPreferenceForAuto() { + /// Returns the maximum zoom level for the current camera position. + Future getMaxZoomPreference() { return _viewApi.getMaxZoomPreference(); } - @override - Future resetMinMaxZoomPreferenceForAuto() { + /// Removes any previously specified upper and lower zoom bounds. + Future resetMinMaxZoomPreference() { return _viewApi.resetMinMaxZoomPreference(); } - @override - Future setMinZoomPreferenceForAuto( - {required double minZoomPreference}) async { + /// Sets a preferred lower bound for the camera zoom. + Future setMinZoomPreference({required double minZoomPreference}) async { try { return await _viewApi.setMinZoomPreference(minZoomPreference); } on PlatformException catch (error) { @@ -396,9 +400,8 @@ mixin CommonAutoMapViewAPI on AutoMapViewAPIInterface { } } - @override - Future setMaxZoomPreferenceForAuto( - {required double maxZoomPreference}) async { + /// Sets a preferred upper bound for the camera zoom. + Future setMaxZoomPreference({required double maxZoomPreference}) async { try { return await _viewApi.setMaxZoomPreference(maxZoomPreference); } on PlatformException catch (error) { @@ -410,8 +413,8 @@ mixin CommonAutoMapViewAPI on AutoMapViewAPIInterface { } } - @override - Future> getMarkersForAuto() async { + /// Get all markers from map view. + Future> getMarkers() async { final List markers = await _viewApi.getMarkers(); return markers .whereType() @@ -419,8 +422,8 @@ mixin CommonAutoMapViewAPI on AutoMapViewAPIInterface { .toList(); } - @override - Future> addMarkersForAuto( + /// Add markers to map view. + Future> addMarkers( {required List markerOptions}) async { // Convert options to pigeon format final List options = @@ -446,9 +449,8 @@ mixin CommonAutoMapViewAPI on AutoMapViewAPIInterface { .toList(); } - @override - Future> updateMarkersForAuto( - {required List markers}) async { + /// Update markers on the map view. + Future> updateMarkers({required List markers}) async { try { final List markerDtos = markers.map((Marker marker) => marker.toDto()).toList(); @@ -467,8 +469,8 @@ mixin CommonAutoMapViewAPI on AutoMapViewAPIInterface { } } - @override - Future removeMarkersForAuto({required List markers}) async { + /// Remove markers from map view. + Future removeMarkers({required List markers}) async { try { final List markerDtos = markers.map((Marker marker) => marker.toDto()).toList(); @@ -482,18 +484,18 @@ mixin CommonAutoMapViewAPI on AutoMapViewAPIInterface { } } - @override - Future clearMarkersForAuto() { + /// Remove all markers from map view. + Future clearMarkers() { return _viewApi.clearMarkers(); } - @override - Future clearForAuto() { + /// Removes all markers, polylines, polygons, overlays, etc from the map. + Future clear() { return _viewApi.clear(); } - @override - Future> getPolygonsForAuto() async { + /// Get all polygons from map view. + Future> getPolygons() async { final List polygons = await _viewApi.getPolygons(); return polygons @@ -502,8 +504,8 @@ mixin CommonAutoMapViewAPI on AutoMapViewAPIInterface { .toList(); } - @override - Future> addPolygonsForAuto( + /// Add polygons to map view. + Future> addPolygons( {required List polygonOptions}) async { // Convert options to pigeon format final List options = @@ -529,8 +531,8 @@ mixin CommonAutoMapViewAPI on AutoMapViewAPIInterface { .toList(); } - @override - Future> updatePolygonsForAuto( + /// Update polygons on the map view. + Future> updatePolygons( {required List polygons}) async { try { final List navigationViewPolygons = @@ -550,8 +552,8 @@ mixin CommonAutoMapViewAPI on AutoMapViewAPIInterface { } } - @override - Future removePolygonsForAuto({required List polygons}) async { + /// Remove polygons from map view. + Future removePolygons({required List polygons}) async { try { final List navigationViewPolygons = polygons.map((Polygon polygon) => polygon.toDto()).toList(); @@ -565,13 +567,13 @@ mixin CommonAutoMapViewAPI on AutoMapViewAPIInterface { } } - @override - Future clearPolygonsForAuto() { + /// Remove all polygons from map view. + Future clearPolygons() { return _viewApi.clearPolygons(); } - @override - Future> getPolylinesForAuto() async { + /// Get all polylines from map view. + Future> getPolylines() async { final List polylines = await _viewApi.getPolylines(); return polylines @@ -580,8 +582,8 @@ mixin CommonAutoMapViewAPI on AutoMapViewAPIInterface { .toList(); } - @override - Future> addPolylinesForAuto( + /// Add polylines to map view. + Future> addPolylines( {required List polylineOptions}) async { // Convert options to pigeon format final List options = @@ -607,8 +609,8 @@ mixin CommonAutoMapViewAPI on AutoMapViewAPIInterface { .toList(); } - @override - Future> updatePolylinesForAuto( + /// Update polylines on the map view. + Future> updatePolylines( {required List polylines}) async { try { final List navigationViewPolylines = polylines @@ -629,9 +631,8 @@ mixin CommonAutoMapViewAPI on AutoMapViewAPIInterface { } } - @override - Future removePolylinesForAuto( - {required List polylines}) async { + /// Remove polylines from map view. + Future removePolylines({required List polylines}) async { try { final List navigationViewPolylines = polylines .map((Polyline polyline) => polyline.toNavigationViewPolyline()) @@ -646,13 +647,13 @@ mixin CommonAutoMapViewAPI on AutoMapViewAPIInterface { } } - @override - Future clearPolylinesForAuto() { + /// Remove all polylines from map view. + Future clearPolylines() { return _viewApi.clearPolylines(); } - @override - Future> getCirclesForAuto() async { + /// Get all circles from map view. + Future> getCircles() async { final List circles = await _viewApi.getCircles(); return circles @@ -661,8 +662,8 @@ mixin CommonAutoMapViewAPI on AutoMapViewAPIInterface { .toList(); } - @override - Future> addCirclesForAuto( + /// Add circles to map view. + Future> addCircles( {required List options}) async { // Convert options to pigeon format final List optionsDto = @@ -688,9 +689,8 @@ mixin CommonAutoMapViewAPI on AutoMapViewAPIInterface { .toList(); } - @override - Future> updateCirclesForAuto( - {required List circles}) async { + /// Update circles on the map view. + Future> updateCircles({required List circles}) async { try { final List navigationViewCircles = circles.map((Circle circle) => circle.toDto()).toList(); @@ -710,8 +710,8 @@ mixin CommonAutoMapViewAPI on AutoMapViewAPIInterface { } } - @override - Future removeCirclesForAuto({required List circles}) async { + /// Remove circles from map view. + Future removeCircles({required List circles}) async { try { final List navigationViewCircles = circles.map((Circle circle) => circle.toDto()).toList(); @@ -725,34 +725,27 @@ mixin CommonAutoMapViewAPI on AutoMapViewAPIInterface { } } - @override - Future clearCirclesForAuto() { + /// Remove all circles from map view. + Future clearCircles() { return _viewApi.clearCircles(); } - @override - Future registerOnCameraChangedListenerForAuto() { + /// Register camera changed listeners. + Future registerOnCameraChangedListener() { return _viewApi.registerOnCameraChangedListener(); } - @override + // Check whether auto screen is available. Future isAutoScreenAvailable() { return _viewApi.isAutoScreenAvailable(); } - Stream _unwrapEventStream() { - // If event that does not - return _autoEventStreamController.stream - .where((_AutoEventWrapper wrapper) => (wrapper.event is T)) - .map((_AutoEventWrapper wrapper) => wrapper.event as T); - } - - @override + /// Get custom navigation auto event stream from the auto view. Stream getCustomNavigationAutoEventStream() { return _unwrapEventStream(); } - @override + /// Get auto screen availibility changed event stream from the auto view. Stream getAutoScreenAvailabilityChangedEventStream() { return _unwrapEventStream(); diff --git a/lib/src/method_channel/common_image_api.dart b/lib/src/method_channel/image_api.dart similarity index 91% rename from lib/src/method_channel/common_image_api.dart rename to lib/src/method_channel/image_api.dart index 43dec0f..ee92117 100644 --- a/lib/src/method_channel/common_image_api.dart +++ b/lib/src/method_channel/image_api.dart @@ -15,13 +15,12 @@ import 'package:flutter/services.dart'; import '../../google_navigation_flutter.dart'; -import '../google_navigation_flutter_platform_interface.dart'; import 'method_channel.dart'; /// @nodoc /// CommonImageRegistryAPI handles image registry API /// actions that are common to both iOS and Android. -mixin CommonImageRegistryAPI on ImageRegistryAPIInterface { +class ImageRegistryAPIImpl { final ImageRegistryApi _imageApi = ImageRegistryApi(); /// Keep track of image count, used to generate image ID's. @@ -32,7 +31,7 @@ mixin CommonImageRegistryAPI on ImageRegistryAPIInterface { return imageId; } - @override + /// Register bitmap to image registry. Future registerBitmapImage( {required Uint8List bitmap, required double imagePixelRatio, @@ -52,12 +51,12 @@ mixin CommonImageRegistryAPI on ImageRegistryAPIInterface { } } - @override + /// Delete bitmap from image registry. Future unregisterImage({required ImageDescriptor imageDescriptor}) { return _imageApi.unregisterImage(imageDescriptor.toDto()); } - @override + /// Get all registered bitmaps from image registry. Future> getRegisteredImages() async { final List registeredImages = await _imageApi.getRegisteredImages(); @@ -67,7 +66,7 @@ mixin CommonImageRegistryAPI on ImageRegistryAPIInterface { .toList(); } - @override + /// Remove all registered bitmaps from image registry. Future clearRegisteredImages() { return _imageApi.clearRegisteredImages(); } diff --git a/lib/src/method_channel/common_view_api.dart b/lib/src/method_channel/map_view_api.dart similarity index 87% rename from lib/src/method_channel/common_view_api.dart rename to lib/src/method_channel/map_view_api.dart index 342dc46..d9efe74 100644 --- a/lib/src/method_channel/common_view_api.dart +++ b/lib/src/method_channel/map_view_api.dart @@ -23,7 +23,7 @@ import 'method_channel.dart'; /// @nodoc /// Class that handles map view and navigation view communications. -mixin CommonMapViewAPI on MapViewAPIInterface { +class MapViewAPIImpl { final MapViewApi _viewApi = MapViewApi(); bool _viewApiHasBeenSetUp = false; final StreamController<_ViewIdEventWrapper> _viewEventStreamController = @@ -61,6 +61,14 @@ mixin CommonMapViewAPI on MapViewAPIInterface { return circleId; } + Stream _unwrapEventStream({required int viewId}) { + // If event that does not + return _viewEventStreamController.stream + .where((_ViewIdEventWrapper wrapper) => + (wrapper.event is T) && wrapper.viewId == viewId) + .map((_ViewIdEventWrapper wrapper) => wrapper.event as T); + } + /// This function ensures that the event API has been setup. This should be /// called when initializing navigation view. void ensureViewAPISetUp() { @@ -134,35 +142,35 @@ mixin CommonMapViewAPI on MapViewAPIInterface { navigationViewOptions: navigationOptionsMessage); } - @override + /// Awaits the platform view to be ready for communication. Future awaitMapReady({required int viewId}) { return _viewApi.awaitMapReady(viewId); } - @override + /// Get the preference for whether the my location should be enabled or disabled. Future isMyLocationEnabled({required int viewId}) { return _viewApi.isMyLocationEnabled(viewId); } - @override + /// Enabled location in the navigation view. Future setMyLocationEnabled( {required int viewId, required bool enabled}) { return _viewApi.setMyLocationEnabled(viewId, enabled); } - @override + /// Get the map type. Future getMapType({required int viewId}) async { final MapTypeDto mapType = await _viewApi.getMapType(viewId); return mapType.toMapType(); } - @override + /// Modified visible map type. Future setMapType( {required int viewId, required MapType mapType}) async { return _viewApi.setMapType(viewId, mapType.toDto()); } - @override + /// Set map style by json string. Future setMapStyle(int viewId, String? styleJson) async { try { // Set the given json to the viewApi or reset the map style if @@ -177,26 +185,26 @@ mixin CommonMapViewAPI on MapViewAPIInterface { } } - @override + /// Enables or disables the my-location button. Future setMyLocationButtonEnabled( {required int viewId, required bool enabled}) { return _viewApi.setMyLocationButtonEnabled(viewId, enabled); } - @override + /// Enables or disables if the my location button consumes click events. Future setConsumeMyLocationButtonClickEventsEnabled( {required int viewId, required bool enabled}) async { return _viewApi.setConsumeMyLocationButtonClickEventsEnabled( viewId, enabled); } - @override + /// Enables or disables the zoom gestures. Future setZoomGesturesEnabled( {required int viewId, required bool enabled}) { return _viewApi.setZoomGesturesEnabled(viewId, enabled); } - @override + /// Enables or disables the zoom controls. Future setZoomControlsEnabled( {required int viewId, required bool enabled}) async { try { @@ -210,36 +218,36 @@ mixin CommonMapViewAPI on MapViewAPIInterface { } } - @override + /// Enables or disables the compass. Future setCompassEnabled({required int viewId, required bool enabled}) { return _viewApi.setCompassEnabled(viewId, enabled); } - @override + /// Sets the preference for whether rotate gestures should be enabled or disabled. Future setRotateGesturesEnabled( {required int viewId, required bool enabled}) { return _viewApi.setRotateGesturesEnabled(viewId, enabled); } - @override + /// Sets the preference for whether scroll gestures should be enabled or disabled. Future setScrollGesturesEnabled( {required int viewId, required bool enabled}) { return _viewApi.setScrollGesturesEnabled(viewId, enabled); } - @override + /// Sets the preference for whether scroll gestures can take place at the same time as a zoom or rotate gesture. Future setScrollGesturesDuringRotateOrZoomEnabled( {required int viewId, required bool enabled}) { return _viewApi.setScrollGesturesDuringRotateOrZoomEnabled(viewId, enabled); } - @override + /// Sets the preference for whether tilt gestures should be enabled or disabled. Future setTiltGesturesEnabled( {required int viewId, required bool enabled}) { return _viewApi.setTiltGesturesEnabled(viewId, enabled); } - @override + /// Sets the preference for whether the Map Toolbar should be enabled or disabled. Future setMapToolbarEnabled( {required int viewId, required bool enabled}) async { try { @@ -253,33 +261,28 @@ mixin CommonMapViewAPI on MapViewAPIInterface { } } - @override + /// Turns the traffic layer on or off. Future setTrafficEnabled({required int viewId, required bool enabled}) { return _viewApi.setTrafficEnabled(viewId, enabled); } - @override + /// Get the preference for whether the my location button should be enabled or disabled. Future isMyLocationButtonEnabled({required int viewId}) { return _viewApi.isMyLocationButtonEnabled(viewId); } - @override + /// Get the preference for whether the my location button consumes click events. Future isConsumeMyLocationButtonClickEventsEnabled( {required int viewId}) { return _viewApi.isConsumeMyLocationButtonClickEventsEnabled(viewId); } - @override - Future isNavigationTripProgressBarEnabled({required int viewId}) { - return _viewApi.isNavigationTripProgressBarEnabled(viewId); - } - - @override + /// Gets the preference for whether zoom gestures should be enabled or disabled. Future isZoomGesturesEnabled({required int viewId}) { return _viewApi.isZoomGesturesEnabled(viewId); } - @override + /// Gets the preference for whether zoom controls should be enabled or disabled. Future isZoomControlsEnabled({required int viewId}) async { try { return await _viewApi.isZoomControlsEnabled(viewId); @@ -292,33 +295,33 @@ mixin CommonMapViewAPI on MapViewAPIInterface { } } - @override + /// Gets the preference for whether compass should be enabled or disabled. Future isCompassEnabled({required int viewId}) { return _viewApi.isCompassEnabled(viewId); } - @override + /// Gets the preference for whether rotate gestures should be enabled or disabled. Future isRotateGesturesEnabled({required int viewId}) { return _viewApi.isRotateGesturesEnabled(viewId); } - @override + /// Gets the preference for whether scroll gestures should be enabled or disabled. Future isScrollGesturesEnabled({required int viewId}) { return _viewApi.isScrollGesturesEnabled(viewId); } - @override + /// Gets the preference for whether scroll gestures can take place at the same time as a zoom or rotate gesture. Future isScrollGesturesEnabledDuringRotateOrZoom( {required int viewId}) { return _viewApi.isScrollGesturesEnabledDuringRotateOrZoom(viewId); } - @override + /// Gets the preference for whether tilt gestures should be enabled or disabled. Future isTiltGesturesEnabled({required int viewId}) { return _viewApi.isTiltGesturesEnabled(viewId); } - @override + /// Gets whether the Map Toolbar is enabled/disabled. Future isMapToolbarEnabled({required int viewId}) async { try { return await _viewApi.isMapToolbarEnabled(viewId); @@ -331,12 +334,12 @@ mixin CommonMapViewAPI on MapViewAPIInterface { } } - @override + /// Checks whether the map is drawing traffic data. Future isTrafficEnabled({required int viewId}) { return _viewApi.isTrafficEnabled(viewId); } - @override + /// Gets users current location. Future getMyLocation({required int viewId}) async { final LatLngDto? myLocation = await _viewApi.getMyLocation(viewId); if (myLocation == null) { @@ -345,7 +348,7 @@ mixin CommonMapViewAPI on MapViewAPIInterface { return myLocation.toLatLng(); } - @override + /// Gets the current position of the camera. Future getCameraPosition({required int viewId}) async { final CameraPositionDto position = await _viewApi.getCameraPosition( viewId, @@ -353,7 +356,7 @@ mixin CommonMapViewAPI on MapViewAPIInterface { return position.toCameraPosition(); } - @override + /// Gets the current visible area / camera bounds. Future getVisibleRegion({required int viewId}) async { final LatLngBoundsDto bounds = await _viewApi.getVisibleRegion( viewId, @@ -364,7 +367,7 @@ mixin CommonMapViewAPI on MapViewAPIInterface { ); } - @override + /// Animates the movement of the camera. Future animateCamera( {required int viewId, required CameraUpdate cameraUpdate, @@ -422,7 +425,7 @@ mixin CommonMapViewAPI on MapViewAPIInterface { } } - @override + /// Moves the camera. Future moveCamera( {required int viewId, required CameraUpdate cameraUpdate}) async { switch (cameraUpdate.type) { @@ -451,7 +454,7 @@ mixin CommonMapViewAPI on MapViewAPIInterface { } } - @override + /// Sets the Camera to follow the location of the user. Future followMyLocation( {required int viewId, required CameraPerspective perspective, @@ -459,110 +462,115 @@ mixin CommonMapViewAPI on MapViewAPIInterface { return _viewApi.followMyLocation(viewId, perspective.toDto(), zoomLevel); } - @override + /// Is the navigation trip progress bar enabled. + Future isNavigationTripProgressBarEnabled({required int viewId}) { + return _viewApi.isNavigationTripProgressBarEnabled(viewId); + } + + /// Enable navigation trip progress bar. Future setNavigationTripProgressBarEnabled( {required int viewId, required bool enabled}) { return _viewApi.setNavigationTripProgressBarEnabled(viewId, enabled); } - @override + /// Is the navigation header enabled. Future isNavigationHeaderEnabled({required int viewId}) { return _viewApi.isNavigationHeaderEnabled(viewId); } - @override + /// Enable navigation header. Future setNavigationHeaderEnabled( {required int viewId, required bool enabled}) { return _viewApi.setNavigationHeaderEnabled(viewId, enabled); } - @override + /// Is the navigation footer enabled. Future isNavigationFooterEnabled({required int viewId}) { return _viewApi.isNavigationFooterEnabled(viewId); } - @override + /// Enable the navigation footer. Future setNavigationFooterEnabled( {required int viewId, required bool enabled}) { return _viewApi.setNavigationFooterEnabled(viewId, enabled); } - @override + /// Is the recenter button enabled. Future isRecenterButtonEnabled({required int viewId}) { return _viewApi.isRecenterButtonEnabled(viewId); } - @override + /// Enable the recenter button. Future setRecenterButtonEnabled( {required int viewId, required bool enabled}) { return _viewApi.setRecenterButtonEnabled(viewId, enabled); } - @override + /// Is the speed limit displayed. Future isSpeedLimitIconEnabled({required int viewId}) { return _viewApi.isSpeedLimitIconEnabled(viewId); } - @override + /// Should display speed limit. Future setSpeedLimitIconEnabled( {required int viewId, required bool enabled}) { return _viewApi.setSpeedLimitIconEnabled(viewId, enabled); } - @override + /// Is speedometer displayed. Future isSpeedometerEnabled({required int viewId}) { return _viewApi.isSpeedometerEnabled(viewId); } - @override + /// Should display speedometer. Future setSpeedometerEnabled( {required int viewId, required bool enabled}) { return _viewApi.setSpeedometerEnabled(viewId, enabled); } - @override + /// Is incident cards displayed. Future isTrafficIncidentCardsEnabled({required int viewId}) { return _viewApi.isTrafficIncidentCardsEnabled(viewId); } - @override + /// Should display incident cards. Future setTrafficIncidentCardsEnabled( {required int viewId, required bool enabled}) { return _viewApi.setTrafficIncidentCardsEnabled(viewId, enabled); } - @override + /// Is navigation UI enabled. Future isNavigationUIEnabled({required int viewId}) { return _viewApi.isNavigationUIEnabled(viewId); } - @override + /// Enable navigation UI. Future setNavigationUIEnabled( {required int viewId, required bool enabled}) { return _viewApi.setNavigationUIEnabled(viewId, enabled); } - @override + /// Show route overview. Future showRouteOverview({required int viewId}) { return _viewApi.showRouteOverview(viewId); } - @override + /// Returns the minimum zoom level. Future getMinZoomPreference({required int viewId}) { return _viewApi.getMinZoomPreference(viewId); } - @override + /// Returns the maximum zoom level for the current camera position. Future getMaxZoomPreference({required int viewId}) { return _viewApi.getMaxZoomPreference(viewId); } - @override + /// Removes any previously specified upper and lower zoom bounds. Future resetMinMaxZoomPreference({required int viewId}) { return _viewApi.resetMinMaxZoomPreference(viewId); } - @override + /// Sets a preferred lower bound for the camera zoom. Future setMinZoomPreference( {required int viewId, required double minZoomPreference}) async { try { @@ -576,7 +584,7 @@ mixin CommonMapViewAPI on MapViewAPIInterface { } } - @override + /// Sets a preferred upper bound for the camera zoom. Future setMaxZoomPreference( {required int viewId, required double maxZoomPreference}) async { try { @@ -590,22 +598,14 @@ mixin CommonMapViewAPI on MapViewAPIInterface { } } - Stream _unwrapEventStream({required int viewId}) { - // If event that does not - return _viewEventStreamController.stream - .where((_ViewIdEventWrapper wrapper) => - (wrapper.event is T) && wrapper.viewId == viewId) - .map((_ViewIdEventWrapper wrapper) => wrapper.event as T); - } - - @override + /// Get navigation recenter button clicked event stream from the navigation view. Stream getNavigationRecenterButtonClickedEventStream({required int viewId}) { return _unwrapEventStream( viewId: viewId); } - @override + /// Get all markers from map view. Future> getMarkers({required int viewId}) async { final List markers = await _viewApi.getMarkers(viewId); return markers @@ -614,7 +614,7 @@ mixin CommonMapViewAPI on MapViewAPIInterface { .toList(); } - @override + /// Add markers to map view. Future> addMarkers( {required int viewId, required List markerOptions}) async { // Convert options to pigeon format @@ -641,7 +641,7 @@ mixin CommonMapViewAPI on MapViewAPIInterface { .toList(); } - @override + /// Update markers on the map view. Future> updateMarkers( {required int viewId, required List markers}) async { try { @@ -662,7 +662,7 @@ mixin CommonMapViewAPI on MapViewAPIInterface { } } - @override + /// Remove markers from map view. Future removeMarkers( {required int viewId, required List markers}) async { try { @@ -678,17 +678,17 @@ mixin CommonMapViewAPI on MapViewAPIInterface { } } - @override + /// Remove all markers from map view. Future clearMarkers({required int viewId}) { return _viewApi.clearMarkers(viewId); } - @override + /// Removes all markers, polylines, polygons, overlays, etc from the map. Future clear({required int viewId}) { return _viewApi.clear(viewId); } - @override + /// Get all polygons from map view. Future> getPolygons({required int viewId}) async { final List polygons = await _viewApi.getPolygons(viewId); @@ -698,7 +698,7 @@ mixin CommonMapViewAPI on MapViewAPIInterface { .toList(); } - @override + /// Add polygons to map view. Future> addPolygons( {required int viewId, required List polygonOptions}) async { @@ -726,7 +726,7 @@ mixin CommonMapViewAPI on MapViewAPIInterface { .toList(); } - @override + /// Update polygons on the map view. Future> updatePolygons( {required int viewId, required List polygons}) async { try { @@ -747,7 +747,7 @@ mixin CommonMapViewAPI on MapViewAPIInterface { } } - @override + /// Remove polygons from map view. Future removePolygons( {required int viewId, required List polygons}) async { try { @@ -763,12 +763,12 @@ mixin CommonMapViewAPI on MapViewAPIInterface { } } - @override + /// Remove all polygons from map view. Future clearPolygons({required int viewId}) { return _viewApi.clearPolygons(viewId); } - @override + /// Get all polylines from map view. Future> getPolylines({required int viewId}) async { final List polylines = await _viewApi.getPolylines(viewId); @@ -778,7 +778,7 @@ mixin CommonMapViewAPI on MapViewAPIInterface { .toList(); } - @override + /// Add polylines to map view. Future> addPolylines( {required int viewId, required List polylineOptions}) async { @@ -806,7 +806,7 @@ mixin CommonMapViewAPI on MapViewAPIInterface { .toList(); } - @override + /// Update polylines on the map view. Future> updatePolylines( {required int viewId, required List polylines}) async { try { @@ -828,7 +828,7 @@ mixin CommonMapViewAPI on MapViewAPIInterface { } } - @override + /// Remove polylines from map view. Future removePolylines( {required int viewId, required List polylines}) async { try { @@ -845,12 +845,12 @@ mixin CommonMapViewAPI on MapViewAPIInterface { } } - @override + /// Remove all polylines from map view. Future clearPolylines({required int viewId}) { return _viewApi.clearPolylines(viewId); } - @override + /// Get all circles from map view. Future> getCircles({required int viewId}) async { final List circles = await _viewApi.getCircles(viewId); @@ -860,7 +860,7 @@ mixin CommonMapViewAPI on MapViewAPIInterface { .toList(); } - @override + /// Add circles to map view. Future> addCircles( {required int viewId, required List options}) async { // Convert options to pigeon format @@ -887,7 +887,7 @@ mixin CommonMapViewAPI on MapViewAPIInterface { .toList(); } - @override + /// Update circles on the map view. Future> updateCircles( {required int viewId, required List circles}) async { try { @@ -909,7 +909,7 @@ mixin CommonMapViewAPI on MapViewAPIInterface { } } - @override + /// Remove circles from map view. Future removeCircles( {required int viewId, required List circles}) async { try { @@ -925,73 +925,73 @@ mixin CommonMapViewAPI on MapViewAPIInterface { } } - @override + /// Remove all circles from map view. Future clearCircles({required int viewId}) { return _viewApi.clearCircles(viewId); } - @override + /// Register camera changed listeners. Future registerOnCameraChangedListener({required int viewId}) { return _viewApi.registerOnCameraChangedListener(viewId); } - @override + /// Get map clicked event stream from the navigation view. Stream getMapClickEventStream({required int viewId}) { return _unwrapEventStream(viewId: viewId); } - @override + /// Get map long clicked event stream from the navigation view. Stream getMapLongClickEventStream({required int viewId}) { return _unwrapEventStream(viewId: viewId); } - @override + /// Get navigation view marker event stream from the navigation view. Stream getMarkerEventStream({required int viewId}) { return _unwrapEventStream(viewId: viewId); } - @override + /// Get navigation view marker drag event stream from the navigation view. Stream getMarkerDragEventStream({required int viewId}) { return _unwrapEventStream(viewId: viewId); } - @override + /// Get navigation view polygon clicked event stream from the navigation view. Stream getPolygonClickedEventStream( {required int viewId}) { return _unwrapEventStream(viewId: viewId); } - @override + /// Get navigation view polyline clicked event stream from the navigation view. Stream getPolylineClickedEventStream( {required int viewId}) { return _unwrapEventStream(viewId: viewId); } - @override + /// Get navigation view circle clicked event stream from the navigation view. Stream getCircleClickedEventStream( {required int viewId}) { return _unwrapEventStream(viewId: viewId); } - @override + /// Get navigation UI changed event stream from the navigation view. Stream getNavigationUIEnabledChangedEventStream({required int viewId}) { return _unwrapEventStream(viewId: viewId); } - @override + /// Get navigation view my location clicked event stream from the navigation view. Stream getMyLocationClickedEventStream( {required int viewId}) { return _unwrapEventStream(viewId: viewId); } - @override + /// Get navigation view my location button clicked event stream from the navigation view. Stream getMyLocationButtonClickedEventStream( {required int viewId}) { return _unwrapEventStream(viewId: viewId); } - @override + /// Get navigation view camera changed event stream from the navigation view. Stream getCameraChangedEventStream( {required int viewId}) { return _unwrapEventStream(viewId: viewId); diff --git a/lib/src/method_channel/method_channel.dart b/lib/src/method_channel/method_channel.dart index d3ddeca..f334e34 100644 --- a/lib/src/method_channel/method_channel.dart +++ b/lib/src/method_channel/method_channel.dart @@ -12,8 +12,9 @@ // See the License for the specific language governing permissions and // limitations under the License. -export 'common_image_api.dart'; -export 'common_session_api.dart'; -export 'common_view_api.dart'; +export 'auto_view_api.dart'; +export 'image_api.dart'; +export 'session_api.dart'; +export 'map_view_api.dart'; export 'convert/convert.dart'; export 'messages.g.dart'; diff --git a/lib/src/method_channel/common_session_api.dart b/lib/src/method_channel/session_api.dart similarity index 95% rename from lib/src/method_channel/common_session_api.dart rename to lib/src/method_channel/session_api.dart index 7bcc257..4b6a418 100644 --- a/lib/src/method_channel/common_session_api.dart +++ b/lib/src/method_channel/session_api.dart @@ -18,14 +18,13 @@ import 'package:flutter/services.dart'; import 'package:stream_transform/stream_transform.dart'; import '../../google_navigation_flutter.dart'; -import '../google_navigation_flutter_platform_interface.dart'; import 'convert/navigation_waypoint.dart'; import 'method_channel.dart'; /// @nodoc /// CommonNavigationSessionAPI handles navigation session API /// actions that are common to both iOS and Android. -mixin CommonNavigationSessionAPI implements NavigationSessionAPIInterface { +class NavigationSessionAPIImpl { bool _sessionApiHasBeenSetUp = false; /// Navigation session pigeon API. @@ -49,7 +48,6 @@ mixin CommonNavigationSessionAPI implements NavigationSessionAPIInterface { } /// Creates navigation session in the native platform and returns navigation session controller. - @override Future createNavigationSession( bool abnormalTerminationReportingEnabled) async { // Setup session API streams. @@ -75,12 +73,12 @@ mixin CommonNavigationSessionAPI implements NavigationSessionAPIInterface { } } - @override + /// Check whether navigator has been initialized. Future isInitialized() async { return _sessionApi.isInitialized(); } - @override + /// Cleanup navigation session. Future cleanup() async { try { return await _sessionApi.cleanup(); @@ -95,7 +93,6 @@ mixin CommonNavigationSessionAPI implements NavigationSessionAPIInterface { } /// Show terms and conditions dialog. - @override Future showTermsAndConditionsDialog(String title, String companyName, bool shouldOnlyShowDriverAwarenessDisclaimer) async { try { @@ -117,13 +114,11 @@ mixin CommonNavigationSessionAPI implements NavigationSessionAPIInterface { } /// Check if terms of service has been accepted. - @override Future areTermsAccepted() { return _sessionApi.areTermsAccepted(); } /// Resets terms of service acceptance state. - @override Future resetTermsAccepted() async { try { return await _sessionApi.resetTermsAccepted(); @@ -137,7 +132,7 @@ mixin CommonNavigationSessionAPI implements NavigationSessionAPIInterface { } } - @override + /// Gets the native navigation SDK version as string. Future getNavSDKVersion() { try { return _sessionApi.getNavSDKVersion(); @@ -151,7 +146,7 @@ mixin CommonNavigationSessionAPI implements NavigationSessionAPIInterface { } } - @override + /// Has guidance been started. Future isGuidanceRunning() async { try { return await _sessionApi.isGuidanceRunning(); @@ -166,7 +161,6 @@ mixin CommonNavigationSessionAPI implements NavigationSessionAPIInterface { } /// Starts navigation guidance. - @override Future startGuidance() async { try { return await _sessionApi.startGuidance(); @@ -181,7 +175,6 @@ mixin CommonNavigationSessionAPI implements NavigationSessionAPIInterface { } /// Stops navigation guidance. - @override Future stopGuidance() async { try { return await _sessionApi.stopGuidance(); @@ -196,7 +189,6 @@ mixin CommonNavigationSessionAPI implements NavigationSessionAPIInterface { } /// Sets destination waypoints and other settings. - @override Future setDestinations(Destinations msg) async { try { final RouteStatusDto status = @@ -216,7 +208,6 @@ mixin CommonNavigationSessionAPI implements NavigationSessionAPIInterface { } /// Clears destinations. - @override Future clearDestinations() async { try { return await _sessionApi.clearDestinations(); @@ -231,7 +222,6 @@ mixin CommonNavigationSessionAPI implements NavigationSessionAPIInterface { } /// Continues to next waypoint. - @override Future continueToNextDestination() async { try { final NavigationWaypointDto? waypointDto = @@ -251,7 +241,6 @@ mixin CommonNavigationSessionAPI implements NavigationSessionAPIInterface { } /// Gets current time and distance left. - @override Future getCurrentTimeAndDistance() async { try { final NavigationTimeAndDistanceDto timeAndDistance = @@ -268,7 +257,6 @@ mixin CommonNavigationSessionAPI implements NavigationSessionAPIInterface { } /// Sets audio guidance settings. - @override Future setAudioGuidance( NavigationAudioGuidanceSettings settings) async { try { @@ -283,8 +271,7 @@ mixin CommonNavigationSessionAPI implements NavigationSessionAPIInterface { } } - /// Sets user location for simulation. - @override + /// Sets user location. Future setUserLocation(LatLng location) async { try { return await _sessionApi.setUserLocation(location.toDto()); @@ -298,8 +285,7 @@ mixin CommonNavigationSessionAPI implements NavigationSessionAPIInterface { } } - /// Unsets previously set user location for the simulation. - @override + /// Unsets user location. Future removeUserLocation() async { try { return await _sessionApi.removeUserLocation(); @@ -314,7 +300,6 @@ mixin CommonNavigationSessionAPI implements NavigationSessionAPIInterface { } /// Simulates locations along existing route. - @override Future simulateLocationsAlongExistingRoute() async { try { return await _sessionApi.simulateLocationsAlongExistingRoute(); @@ -329,7 +314,6 @@ mixin CommonNavigationSessionAPI implements NavigationSessionAPIInterface { } /// Simulates locations along existing route with simulation options. - @override Future simulateLocationsAlongExistingRouteWithOptions( SimulationOptions options) async { try { @@ -346,7 +330,6 @@ mixin CommonNavigationSessionAPI implements NavigationSessionAPIInterface { } /// Simulates locations along new route. - @override Future simulateLocationsAlongNewRoute( List waypoints) async { try { @@ -368,7 +351,6 @@ mixin CommonNavigationSessionAPI implements NavigationSessionAPIInterface { } /// Simulates locations along new route with routing and simulation options. - @override Future simulateLocationsAlongNewRouteWithRoutingAndSimulationOptions( List waypoints, @@ -397,7 +379,6 @@ mixin CommonNavigationSessionAPI implements NavigationSessionAPIInterface { } /// Simulates locations along new route with routing options. - @override Future simulateLocationsAlongNewRouteWithRoutingOptions( List waypoints, @@ -424,7 +405,6 @@ mixin CommonNavigationSessionAPI implements NavigationSessionAPIInterface { } /// Pauses simulation. - @override Future pauseSimulation() async { try { return await _sessionApi.pauseSimulation(); @@ -439,7 +419,6 @@ mixin CommonNavigationSessionAPI implements NavigationSessionAPIInterface { } /// Resumes simulation. - @override Future resumeSimulation() async { try { return await _sessionApi.resumeSimulation(); @@ -454,7 +433,6 @@ mixin CommonNavigationSessionAPI implements NavigationSessionAPIInterface { } /// Sets state of allow background location updates. (iOS only) - @override Future allowBackgroundLocationUpdates(bool allow) async { try { return await _sessionApi.allowBackgroundLocationUpdates(allow); @@ -469,7 +447,6 @@ mixin CommonNavigationSessionAPI implements NavigationSessionAPIInterface { } /// Enables road snapped location updates. - @override Future enableRoadSnappedLocationUpdates() async { try { return await _sessionApi.enableRoadSnappedLocationUpdates(); @@ -484,7 +461,6 @@ mixin CommonNavigationSessionAPI implements NavigationSessionAPIInterface { } /// Disables road snapped location updates. - @override Future disableRoadSnappedLocationUpdates() async { try { return await _sessionApi.disableRoadSnappedLocationUpdates(); @@ -499,7 +475,6 @@ mixin CommonNavigationSessionAPI implements NavigationSessionAPIInterface { } /// Enables navigation info updates. - @override Future enableTurnByTurnNavigationEvents( int? numNextStepsToPreview) async { try { @@ -516,7 +491,6 @@ mixin CommonNavigationSessionAPI implements NavigationSessionAPIInterface { } /// Disables navigation info updates. - @override Future disableTurnByTurnNavigationEvents() async { try { return await _sessionApi.disableTurnByTurnNavigationEvents(); @@ -531,7 +505,6 @@ mixin CommonNavigationSessionAPI implements NavigationSessionAPIInterface { } /// Get route segments. - @override Future> getRouteSegments() async { try { final List routeSegments = @@ -552,7 +525,6 @@ mixin CommonNavigationSessionAPI implements NavigationSessionAPIInterface { } /// Get traveled route. - @override Future> getTraveledRoute() async { try { final List traveledRoute = @@ -574,7 +546,6 @@ mixin CommonNavigationSessionAPI implements NavigationSessionAPIInterface { } /// Get current route segment. - @override Future getCurrentRouteSegment() async { try { final RouteSegmentDto? currentRouteSegment = @@ -590,24 +561,22 @@ mixin CommonNavigationSessionAPI implements NavigationSessionAPIInterface { } } - /// Get event stream for speeding. - @override + /// Get navigation speeding event stream from the navigation session. Stream getNavigationSpeedingEventStream() { return _sessionEventStreamController.stream .whereType() .map((SpeedingUpdatedEventDto event) => event.toSpeedingUpdatedEvent()); } - /// Get event stream for road snapped location updates. - @override + /// Get navigation road snapped location event stream from the navigation session. Stream getNavigationRoadSnappedLocationEventStream() { return _sessionEventStreamController.stream .whereType(); } - /// Get event stream for road snapped location updates. - @override + /// Get navigation road snapped raw location event stream from the navigation session. + /// Android only. Stream getNavigationRoadSnappedRawLocationEventStream() { return _sessionEventStreamController.stream @@ -615,13 +584,11 @@ mixin CommonNavigationSessionAPI implements NavigationSessionAPIInterface { } /// Get navigation on arrival event stream from the navigation session. - @override Stream getNavigationOnArrivalEventStream() { return _sessionEventStreamController.stream.whereType(); } /// Get navigation on rerouting event stream from the navigation session. - @override Stream getNavigationOnReroutingEventStream() { return _sessionEventStreamController.stream .whereType<_ReroutingEvent>() @@ -629,7 +596,6 @@ mixin CommonNavigationSessionAPI implements NavigationSessionAPIInterface { } /// Get navigation on GPS availability update event stream from the navigation session. - @override Stream getNavigationOnGpsAvailabilityUpdateEventStream() { return _sessionEventStreamController.stream @@ -637,7 +603,6 @@ mixin CommonNavigationSessionAPI implements NavigationSessionAPIInterface { } /// Get navigation traffic updated event stream from the navigation session. - @override Stream getNavigationTrafficUpdatedEventStream() { return _sessionEventStreamController.stream .whereType<_TrafficUpdatedEvent>() @@ -645,7 +610,6 @@ mixin CommonNavigationSessionAPI implements NavigationSessionAPIInterface { } /// Get navigation on route changed event stream from the navigation session. - @override Stream getNavigationOnRouteChangedEventStream() { return _sessionEventStreamController.stream .whereType<_RouteChangedEvent>() @@ -653,14 +617,13 @@ mixin CommonNavigationSessionAPI implements NavigationSessionAPIInterface { } /// Get navigation remaining time or distance event stream from the navigation session. - @override Stream getNavigationRemainingTimeOrDistanceChangedEventStream() { return _sessionEventStreamController.stream .whereType(); } - @override + /// Register remaining time or distance change listener with thresholds. Future registerRemainingTimeOrDistanceChangedListener( int remainingTimeThresholdSeconds, int remainingDistanceThresholdMeters) { return _sessionApi.registerRemainingTimeOrDistanceChangedListener( @@ -668,7 +631,6 @@ mixin CommonNavigationSessionAPI implements NavigationSessionAPIInterface { } /// Get navigation info event stream from the navigation session. - @override Stream getNavInfoStream() { return _sessionEventStreamController.stream.whereType(); } diff --git a/lib/src/navigator/google_navigation_flutter_navigator.dart b/lib/src/navigator/google_navigation_flutter_navigator.dart index 518e8c6..eb6bf50 100644 --- a/lib/src/navigator/google_navigation_flutter_navigator.dart +++ b/lib/src/navigator/google_navigation_flutter_navigator.dart @@ -51,14 +51,14 @@ class GoogleMapsNavigator { /// static Future initializeNavigationSession( {bool abnormalTerminationReportingEnabled = true}) async { - await GoogleMapsNavigationPlatform.instance + await GoogleMapsNavigationPlatform.instance.navigationSessionAPI .createNavigationSession(abnormalTerminationReportingEnabled); // Enable road-snapped location updates if there are subscriptions to them. if ((_roadSnappedLocationUpdatedController?.hasListener ?? false) || (_roadSnappedRawLocationUpdatedController?.hasListener ?? false) || (_gpsAvailabilityUpdatedController?.hasListener ?? false)) { - await GoogleMapsNavigationPlatform.instance + await GoogleMapsNavigationPlatform.instance.navigationSessionAPI .enableRoadSnappedLocationUpdates(); } } @@ -70,7 +70,8 @@ class GoogleMapsNavigator { /// navigation session must be re-initialized with [initializeNavigationSession]. /// After initialization guidance state can be checked with [isGuidanceRunning]. static Future isInitialized() async { - return GoogleMapsNavigationPlatform.instance.isInitialized(); + return GoogleMapsNavigationPlatform.instance.navigationSessionAPI + .isInitialized(); } /// Sets the event channel listener for the [SpeedingUpdatedEvent]s. @@ -91,7 +92,7 @@ class GoogleMapsNavigator { static StreamSubscription setSpeedingUpdatedListener( OnSpeedingUpdatedEventCallback listener, ) { - return GoogleMapsNavigationPlatform.instance + return GoogleMapsNavigationPlatform.instance.navigationSessionAPI .getNavigationSpeedingEventStream() .listen(listener); } @@ -113,7 +114,7 @@ class GoogleMapsNavigator { /// ``` static StreamSubscription setOnArrivalListener( OnArrivalEventCallback listener) { - return GoogleMapsNavigationPlatform.instance + return GoogleMapsNavigationPlatform.instance.navigationSessionAPI .getNavigationOnArrivalEventStream() .listen(listener); } @@ -135,7 +136,7 @@ class GoogleMapsNavigator { /// ``` static StreamSubscription setOnReroutingListener( OnReroutingEventCallback listener) { - return GoogleMapsNavigationPlatform.instance + return GoogleMapsNavigationPlatform.instance.navigationSessionAPI .getNavigationOnReroutingEventStream() .listen((void event) { listener.call(); @@ -172,11 +173,11 @@ class GoogleMapsNavigator { StreamController.broadcast(onCancel: () { _disableRoadSnappedLocationUpdatesIfNoActiveListeners(); }, onListen: () { - GoogleMapsNavigationPlatform.instance + GoogleMapsNavigationPlatform.instance.navigationSessionAPI .enableRoadSnappedLocationUpdates(); }); unawaited(_gpsAvailabilityUpdatedController!.addStream( - GoogleMapsNavigationPlatform.instance + GoogleMapsNavigationPlatform.instance.navigationSessionAPI .getNavigationOnGpsAvailabilityUpdateEventStream())); } @@ -203,7 +204,7 @@ class GoogleMapsNavigator { /// ``` static StreamSubscription setTrafficUpdatedListener( OnTrafficUpdatedEventCallback listener) { - return GoogleMapsNavigationPlatform.instance + return GoogleMapsNavigationPlatform.instance.navigationSessionAPI .getNavigationTrafficUpdatedEventStream() .listen((void event) { listener.call(); @@ -227,7 +228,7 @@ class GoogleMapsNavigator { /// ``` static StreamSubscription setOnRouteChangedListener( OnRouteChangedEventCallback listener) { - return GoogleMapsNavigationPlatform.instance + return GoogleMapsNavigationPlatform.instance.navigationSessionAPI .getNavigationOnRouteChangedEventStream() .listen((void event) { listener.call(); @@ -257,10 +258,10 @@ class GoogleMapsNavigator { }) { assert(remainingTimeThresholdSeconds >= 0); assert(remainingDistanceThresholdMeters >= 0); - GoogleMapsNavigationPlatform.instance + GoogleMapsNavigationPlatform.instance.navigationSessionAPI .registerRemainingTimeOrDistanceChangedListener( remainingTimeThresholdSeconds, remainingDistanceThresholdMeters); - return GoogleMapsNavigationPlatform.instance + return GoogleMapsNavigationPlatform.instance.navigationSessionAPI .getNavigationRemainingTimeOrDistanceChangedEventStream() .listen(listener); } @@ -298,16 +299,17 @@ class GoogleMapsNavigator { _navInfoEventStreamController = StreamController.broadcast( onCancel: () { if (_navInfoEventStreamController?.hasListener ?? false) { - GoogleMapsNavigationPlatform.instance + GoogleMapsNavigationPlatform.instance.navigationSessionAPI .disableTurnByTurnNavigationEvents(); } }, ); - unawaited(_navInfoEventStreamController! - .addStream(GoogleMapsNavigationPlatform.instance.getNavInfoStream())); + unawaited(_navInfoEventStreamController!.addStream( + GoogleMapsNavigationPlatform.instance.navigationSessionAPI + .getNavInfoStream())); } - GoogleMapsNavigationPlatform.instance + GoogleMapsNavigationPlatform.instance.navigationSessionAPI .enableTurnByTurnNavigationEvents(numNextStepsToPreview); return _navInfoEventStreamController!.stream.listen(listener); @@ -343,12 +345,12 @@ class GoogleMapsNavigator { _disableRoadSnappedLocationUpdatesIfNoActiveListeners(); }, onListen: () { - GoogleMapsNavigationPlatform.instance + GoogleMapsNavigationPlatform.instance.navigationSessionAPI .enableRoadSnappedLocationUpdates(); }, ); unawaited(_roadSnappedLocationUpdatedController!.addStream( - GoogleMapsNavigationPlatform.instance + GoogleMapsNavigationPlatform.instance.navigationSessionAPI .getNavigationRoadSnappedLocationEventStream())); } @@ -386,12 +388,12 @@ class GoogleMapsNavigator { _disableRoadSnappedLocationUpdatesIfNoActiveListeners(); }, onListen: () { - GoogleMapsNavigationPlatform.instance + GoogleMapsNavigationPlatform.instance.navigationSessionAPI .enableRoadSnappedLocationUpdates(); }, ); unawaited(_roadSnappedRawLocationUpdatedController!.addStream( - GoogleMapsNavigationPlatform.instance + GoogleMapsNavigationPlatform.instance.navigationSessionAPI .getNavigationRoadSnappedRawLocationEventStream())); } @@ -403,7 +405,8 @@ class GoogleMapsNavigator { if (!(_roadSnappedLocationUpdatedController?.hasListener ?? false) && !(_roadSnappedRawLocationUpdatedController?.hasListener ?? false) && !(_gpsAvailabilityUpdatedController?.hasListener ?? false)) { - GoogleMapsNavigationPlatform.instance.disableRoadSnappedLocationUpdates(); + GoogleMapsNavigationPlatform.instance.navigationSessionAPI + .disableRoadSnappedLocationUpdates(); } } @@ -419,7 +422,7 @@ class GoogleMapsNavigator { /// On Android the session is cleaned up, but never destroyed after the /// first initialization. static Future cleanup() async { - await GoogleMapsNavigationPlatform.instance.cleanup(); + await GoogleMapsNavigationPlatform.instance.navigationSessionAPI.cleanup(); } /// Shows terms and conditions dialog. @@ -435,13 +438,15 @@ class GoogleMapsNavigator { static Future showTermsAndConditionsDialog( String title, String companyName, {bool shouldOnlyShowDriverAwarenessDisclaimer = false}) async { - return GoogleMapsNavigationPlatform.instance.showTermsAndConditionsDialog( - title, companyName, shouldOnlyShowDriverAwarenessDisclaimer); + return GoogleMapsNavigationPlatform.instance.navigationSessionAPI + .showTermsAndConditionsDialog( + title, companyName, shouldOnlyShowDriverAwarenessDisclaimer); } /// Checks if terms and conditions have already been accepted by the user. static Future areTermsAccepted() async { - return GoogleMapsNavigationPlatform.instance.areTermsAccepted(); + return GoogleMapsNavigationPlatform.instance.navigationSessionAPI + .areTermsAccepted(); } /// Resets the terms of service acceptance state. @@ -449,27 +454,32 @@ class GoogleMapsNavigator { /// If the navigation session has already been initialized /// throws [ResetTermsAndConditionsException]. static Future resetTermsAccepted() async { - return GoogleMapsNavigationPlatform.instance.resetTermsAccepted(); + return GoogleMapsNavigationPlatform.instance.navigationSessionAPI + .resetTermsAccepted(); } /// Gets the native navigation SDK version as string. static Future getNavSDKVersion() async { - return GoogleMapsNavigationPlatform.instance.getNavSDKVersion(); + return GoogleMapsNavigationPlatform.instance.navigationSessionAPI + .getNavSDKVersion(); } /// Starts the navigation guidance. static Future startGuidance() { - return GoogleMapsNavigationPlatform.instance.startGuidance(); + return GoogleMapsNavigationPlatform.instance.navigationSessionAPI + .startGuidance(); } /// Stops the navigation guidance. static Future stopGuidance() { - return GoogleMapsNavigationPlatform.instance.stopGuidance(); + return GoogleMapsNavigationPlatform.instance.navigationSessionAPI + .stopGuidance(); } /// Check if guidance is running. static Future isGuidanceRunning() { - return GoogleMapsNavigationPlatform.instance.isGuidanceRunning(); + return GoogleMapsNavigationPlatform.instance.navigationSessionAPI + .isGuidanceRunning(); } /// Sets one or multiple destinations for navigation. @@ -483,12 +493,14 @@ class GoogleMapsNavigator { /// be used. static Future setDestinations( Destinations destinations) { - return GoogleMapsNavigationPlatform.instance.setDestinations(destinations); + return GoogleMapsNavigationPlatform.instance.navigationSessionAPI + .setDestinations(destinations); } /// Clears existing destinations. static Future clearDestinations() { - return GoogleMapsNavigationPlatform.instance.clearDestinations(); + return GoogleMapsNavigationPlatform.instance.navigationSessionAPI + .clearDestinations(); } /// Continues to the next waypoint. @@ -497,52 +509,59 @@ class GoogleMapsNavigator { /// Following this call, guidance will be toward the next destination, /// and information about the old destination is not available. static Future continueToNextDestination() { - return GoogleMapsNavigationPlatform.instance.continueToNextDestination(); + return GoogleMapsNavigationPlatform.instance.navigationSessionAPI + .continueToNextDestination(); } /// Returns how much current time and distance are left. static Future getCurrentTimeAndDistance() { - return GoogleMapsNavigationPlatform.instance.getCurrentTimeAndDistance(); + return GoogleMapsNavigationPlatform.instance.navigationSessionAPI + .getCurrentTimeAndDistance(); } /// Sets the audio guidance settings. static Future setAudioGuidance( NavigationAudioGuidanceSettings settings) { - return GoogleMapsNavigationPlatform.instance.setAudioGuidance(settings); + return GoogleMapsNavigationPlatform.instance.navigationSessionAPI + .setAudioGuidance(settings); } /// Sets state of allow background location updates. (iOS only) /// /// Throws [UnsupportedError] on Android. static Future allowBackgroundLocationUpdates(bool allow) { - return GoogleMapsNavigationPlatform.instance.allowBackgroundLocationUpdates( + return GoogleMapsNavigationPlatform.instance.navigationSessionAPI + .allowBackgroundLocationUpdates( allow, ); } /// Get route segments. static Future> getRouteSegments() { - return GoogleMapsNavigationPlatform.instance.getRouteSegments(); + return GoogleMapsNavigationPlatform.instance.navigationSessionAPI + .getRouteSegments(); } /// Get traveled route. static Future> getTraveledRoute() { - return GoogleMapsNavigationPlatform.instance.getTraveledRoute(); + return GoogleMapsNavigationPlatform.instance.navigationSessionAPI + .getTraveledRoute(); } /// Get current route segment. static Future getCurrentRouteSegment() { - return GoogleMapsNavigationPlatform.instance.getCurrentRouteSegment(); + return GoogleMapsNavigationPlatform.instance.navigationSessionAPI + .getCurrentRouteSegment(); } static Future enableTurnByTurnNavigationEvents( int? numNextStepsToPreview) { - return GoogleMapsNavigationPlatform.instance + return GoogleMapsNavigationPlatform.instance.navigationSessionAPI .enableTurnByTurnNavigationEvents(numNextStepsToPreview); } static Future disableTurnByTurnNavigationEvents() { - return GoogleMapsNavigationPlatform.instance + return GoogleMapsNavigationPlatform.instance.navigationSessionAPI .disableTurnByTurnNavigationEvents(); } } diff --git a/lib/src/navigator/google_navigation_flutter_simulator.dart b/lib/src/navigator/google_navigation_flutter_simulator.dart index b87b074..2fbb8d5 100644 --- a/lib/src/navigator/google_navigation_flutter_simulator.dart +++ b/lib/src/navigator/google_navigation_flutter_simulator.dart @@ -20,19 +20,21 @@ import '../google_navigation_flutter_platform_interface.dart'; class Simulator { /// Sets user location. Future setUserLocation(LatLng location) { - return GoogleMapsNavigationPlatform.instance.setUserLocation( + return GoogleMapsNavigationPlatform.instance.navigationSessionAPI + .setUserLocation( location, ); } /// Stops simulation by unsetting user location simulation. Future removeUserLocation() { - return GoogleMapsNavigationPlatform.instance.removeUserLocation(); + return GoogleMapsNavigationPlatform.instance.navigationSessionAPI + .removeUserLocation(); } /// Simulates locations along existing route. Future simulateLocationsAlongExistingRoute() { - return GoogleMapsNavigationPlatform.instance + return GoogleMapsNavigationPlatform.instance.navigationSessionAPI .simulateLocationsAlongExistingRoute(); } @@ -40,7 +42,7 @@ class Simulator { Future simulateLocationsAlongExistingRouteWithOptions( SimulationOptions options, ) { - return GoogleMapsNavigationPlatform.instance + return GoogleMapsNavigationPlatform.instance.navigationSessionAPI .simulateLocationsAlongExistingRouteWithOptions( options, ); @@ -50,7 +52,8 @@ class Simulator { Future simulateLocationsAlongNewRoute( List waypoints, ) { - return GoogleMapsNavigationPlatform.instance.simulateLocationsAlongNewRoute( + return GoogleMapsNavigationPlatform.instance.navigationSessionAPI + .simulateLocationsAlongNewRoute( waypoints, ); } @@ -61,7 +64,7 @@ class Simulator { List waypoints, RoutingOptions routingOptions, ) { - return GoogleMapsNavigationPlatform.instance + return GoogleMapsNavigationPlatform.instance.navigationSessionAPI .simulateLocationsAlongNewRouteWithRoutingOptions( waypoints, routingOptions, @@ -75,7 +78,7 @@ class Simulator { RoutingOptions routingOptions, SimulationOptions simulationOptions, ) { - return GoogleMapsNavigationPlatform.instance + return GoogleMapsNavigationPlatform.instance.navigationSessionAPI .simulateLocationsAlongNewRouteWithRoutingAndSimulationOptions( waypoints, routingOptions, @@ -85,11 +88,13 @@ class Simulator { /// Pauses simulation. Future pauseSimulation() { - return GoogleMapsNavigationPlatform.instance.pauseSimulation(); + return GoogleMapsNavigationPlatform.instance.navigationSessionAPI + .pauseSimulation(); } /// Resumes simulation. Future resumeSimulation() { - return GoogleMapsNavigationPlatform.instance.resumeSimulation(); + return GoogleMapsNavigationPlatform.instance.navigationSessionAPI + .resumeSimulation(); } }