diff --git a/packages/google_maps_flutter/CHANGELOG.md b/packages/google_maps_flutter/CHANGELOG.md index 840c63495..913726b48 100644 --- a/packages/google_maps_flutter/CHANGELOG.md +++ b/packages/google_maps_flutter/CHANGELOG.md @@ -1,7 +1,9 @@ -## NEXT +## 0.1.6 * Fix new lint warnings. * Update minimum Flutter and Dart version to 3.13 and 3.1. +* Update webview_flutter to 4.2.2. +* Update webview_flutter_lwe to 0.3.0. ## 0.1.5 diff --git a/packages/google_maps_flutter/README.md b/packages/google_maps_flutter/README.md index f1aee9afe..cbb2abde5 100644 --- a/packages/google_maps_flutter/README.md +++ b/packages/google_maps_flutter/README.md @@ -21,7 +21,7 @@ This package is not an _endorsed_ implementation of `google_maps_flutter`. There ```yaml dependencies: google_maps_flutter: ^2.1.7 - google_maps_flutter_tizen: ^0.1.5 + google_maps_flutter_tizen: ^0.1.6 ``` For detailed usage, see https://pub.dev/packages/google_maps_flutter#sample-usage. diff --git a/packages/google_maps_flutter/lib/src/circle.dart b/packages/google_maps_flutter/lib/src/circle.dart index 3acf17428..197f3e09a 100644 --- a/packages/google_maps_flutter/lib/src/circle.dart +++ b/packages/google_maps_flutter/lib/src/circle.dart @@ -12,7 +12,7 @@ class CircleController { required util.GCircle circle, bool consumeTapEvents = false, ui.VoidCallback? onTap, - Future? controller, + WebViewController? controller, }) : _circle = circle, _consumeTapEvents = consumeTapEvents, tapEvent = onTap { @@ -25,10 +25,10 @@ class CircleController { /// Circle component's tap event. ui.VoidCallback? tapEvent; - Future _addCircleEvent(Future? controller) async { + Future _addCircleEvent(WebViewController? controller) async { final String command = "$_circle.addListener('click', (event) => CircleClick.postMessage(JSON.stringify(${_circle?.id})));"; - await (await controller!).runJavascript(command); + await controller!.runJavaScript(command); } /// Returns `true` if this Controller will use its own `onTap` handler to consume events. diff --git a/packages/google_maps_flutter/lib/src/google_maps_controller.dart b/packages/google_maps_flutter/lib/src/google_maps_controller.dart index cc8a97b24..c7f064c69 100644 --- a/packages/google_maps_flutter/lib/src/google_maps_controller.dart +++ b/packages/google_maps_flutter/lib/src/google_maps_controller.dart @@ -43,22 +43,23 @@ class GoogleMapsController { final Set _polygons; final Set _polylines; final Set _circles; + final Completer _pageFinishedCompleter = Completer(); + WebViewWidget? _webview; // The raw options passed by the user, before converting to maps. // Caching this allows us to re-create the map faithfully when needed. Map _rawMapOptions = {}; - WebView? _widget; - final Completer _controller = - Completer(); + /// Webview controller instance. + final WebViewController controller = WebViewController(); - /// Returns webview controller instance. - Future get controller => _controller.future; + /// The Flutter widget that will contain the rendered Map. Used for caching. + WebViewWidget? get webview => _webview; /// Returns min-max zoom levels. Test only. @visibleForTesting Future getMinMaxZoomLevels() async { - final String value = await (await controller).runJavascriptReturningResult( - 'JSON.stringify([map.minZoom, map.maxZoom])'); + final String value = await controller.runJavaScriptReturningResult( + 'JSON.stringify([map.minZoom, map.maxZoom])') as String; final dynamic bound = json.decode(value); double min = 0, max = 0; if (bound is List) { @@ -80,25 +81,24 @@ class GoogleMapsController { /// Returns if zoomGestures property is enabled. Test only. @visibleForTesting Future isZoomGesturesEnabled() async { - final String value = await (await controller) - .runJavascriptReturningResult('map.gestureHandling'); + final String value = await controller + .runJavaScriptReturningResult('map.gestureHandling') as String; return value != 'none'; } - @visibleForTesting - /// Returns if zoomControls property is enabled. Test only. + @visibleForTesting Future isZoomControlsEnabled() async { - final String value = await (await controller) - .runJavascriptReturningResult('map.zoomControl'); + final String value = await controller + .runJavaScriptReturningResult('map.zoomControl') as String; return value != 'false'; } /// Returns if scrollGestures property is enabled. Test only. @visibleForTesting Future isScrollGesturesEnabled() async { - final String value = await (await controller) - .runJavascriptReturningResult('map.gestureHandling'); + final String value = await controller + .runJavaScriptReturningResult('map.gestureHandling') as String; return value != 'none'; } @@ -108,35 +108,62 @@ class GoogleMapsController { return _isTrafficLayerEnabled(_rawMapOptions); } - late WebViewController _temp; void _getWebview() { // If the variable does not exist, we must find other alternatives. String path = Platform.environment['AUL_ROOT_PATH'] ?? ''; path += '/res/flutter_assets/assets/map.html'; - - _widget = WebView( - initialUrl: path, - javascriptMode: JavascriptMode.unrestricted, - onWebViewCreated: (WebViewController webViewController) async { - _temp = webViewController; - }, - javascriptChannels: { - _onBoundsChanged(), - _onIdle(), - _onTilesloaded(), - _onClick(), - _onRightClick(), - _onMarkerClick(), - _onMarkerDragEnd(), - _onPolylineClick(), - _onPolygonClick(), - _onCircleClick(), - }, - onPageFinished: (String url) async { - _controller.complete(_temp); - }, - gestureNavigationEnabled: true, - ); + controller + ..setNavigationDelegate( + NavigationDelegate( + onPageFinished: (String url) { + _pageFinishedCompleter.complete(true); + }, + ), + ) + ..setJavaScriptMode(JavaScriptMode.unrestricted) + ..addJavaScriptChannel( + 'BoundChanged', + onMessageReceived: _onBoundsChanged, + ) + ..addJavaScriptChannel( + 'Idle', + onMessageReceived: _onIdle, + ) + ..addJavaScriptChannel( + 'Tilesloaded', + onMessageReceived: _onTilesloaded, + ) + ..addJavaScriptChannel( + 'Click', + onMessageReceived: _onClick, + ) + ..addJavaScriptChannel( + 'RightClick', + onMessageReceived: _onRightClick, + ) + ..addJavaScriptChannel( + 'MarkerClick', + onMessageReceived: _onMarkerClick, + ) + ..addJavaScriptChannel( + 'MarkerDragEnd', + onMessageReceived: _onMarkerDragEnd, + ) + ..addJavaScriptChannel( + 'PolylineClick', + onMessageReceived: _onPolylineClick, + ) + ..addJavaScriptChannel( + 'PolygonClick', + onMessageReceived: _onPolygonClick, + ) + ..addJavaScriptChannel( + 'CircleClick', + onMessageReceived: _onCircleClick, + ) + ..loadFile(path); + + _webview = WebViewWidget(controller: controller); } Future _createMap() async { @@ -149,16 +176,7 @@ class GoogleMapsController { map.addListener('rightclick', (event) => RightClick.postMessage(JSON.stringify(event))); map.addListener('tilesloaded', Tilesloaded.postMessage); '''; - await (await controller).runJavascript(command); - } - - /// The Flutter widget that will contain the rendered Map. Used for caching. - Widget? get widget { - if (_widget == null && !_streamController.isClosed) { - _getWebview(); - _createMap(); - } - return _widget; + await controller.runJavaScript(command); } String _createOptions() { @@ -184,225 +202,156 @@ class GoogleMapsController { // Keeps track if the map is moving or not. bool _mapIsMoving = false; - JavascriptChannel _onBoundsChanged() { - return JavascriptChannel( - name: 'BoundChanged', - onMessageReceived: (JavascriptMessage message) async { - if (_widget == null) { - return; - } - final LatLng center = await getCenter(); - final double zoom = await getZoomLevel(); - - if (!_streamController.isClosed) { - if (!_mapIsMoving) { - _mapIsMoving = true; - _streamController.add(CameraMoveStartedEvent(_mapId)); - } - - _streamController.add( - CameraMoveEvent( - _mapId, CameraPosition(target: center, zoom: zoom)), - ); - } - }); + Future _onBoundsChanged(JavaScriptMessage message) async { + final LatLng center = await getCenter(); + final num zoom = await getZoomLevel(); + + if (!_streamController.isClosed) { + if (!_mapIsMoving) { + _mapIsMoving = true; + _streamController.add(CameraMoveStartedEvent(_mapId)); + } + + _streamController.add( + CameraMoveEvent( + _mapId, CameraPosition(target: center, zoom: zoom.toDouble())), + ); + } } - JavascriptChannel _onIdle() { - return JavascriptChannel( - name: 'Idle', - onMessageReceived: (JavascriptMessage message) async { - if (_widget == null) { - return; - } - _mapIsMoving = false; - _streamController.add(CameraIdleEvent(_mapId)); - }); + void _onIdle(JavaScriptMessage message) { + _mapIsMoving = false; + _streamController.add(CameraIdleEvent(_mapId)); } - JavascriptChannel _onTilesloaded() { - return JavascriptChannel( - name: 'Tilesloaded', - onMessageReceived: (JavascriptMessage message) async { - if (_widget == null || _isFirst) { - return; - } - try { - _streamController.add(MapReadyEvent(_mapId)); - _isFirst = true; - } catch (e) { - debugPrint('Javascript Error: $e'); - } - }); + void _onTilesloaded(JavaScriptMessage message) { + try { + if (_isFirst) { + return; + } + _streamController.add(MapReadyEvent(_mapId)); + _isFirst = true; + } catch (e) { + debugPrint('JavaScript Error: $e'); + } } - JavascriptChannel _onClick() { - return JavascriptChannel( - name: 'Click', - onMessageReceived: (JavascriptMessage message) async { - if (_widget == null) { - return; - } - try { - final dynamic event = json.decode(message.message); - if (event is Map) { - assert(event['latLng'] != null); - final LatLng position = LatLng(event['latLng']['lat'] as double, - event['latLng']['lng'] as double); - _streamController.add(MapTapEvent(_mapId, position)); - } - } catch (e) { - debugPrint('Javascript Error: $e'); - } - }); + void _onClick(JavaScriptMessage message) { + try { + final dynamic event = json.decode(message.message); + if (event is Map) { + assert(event['latLng'] != null); + final LatLng position = LatLng( + event['latLng']['lat'] as double, event['latLng']['lng'] as double); + _streamController.add(MapTapEvent(_mapId, position)); + } + } catch (e) { + debugPrint('JavaScript Error: $e'); + } } - JavascriptChannel _onRightClick() { - // LWE does not support a long press event yet. - return JavascriptChannel( - name: 'RightClick', - onMessageReceived: (JavascriptMessage message) async { - if (_widget == null) { - return; - } - try { - final dynamic event = json.decode(message.message); - if (event is Map) { - assert(event['latLng'] != null); - final LatLng position = LatLng(event['latLng']['lat'] as double, - event['latLng']['lng'] as double); - _streamController.add(MapLongPressEvent(_mapId, position)); - } - } catch (e) { - debugPrint('Javascript Error: $e'); - } - }); + void _onRightClick(JavaScriptMessage message) { + try { + final dynamic event = json.decode(message.message); + if (event is Map) { + assert(event['latLng'] != null); + final LatLng position = LatLng( + event['latLng']['lat'] as double, event['latLng']['lng'] as double); + _streamController.add(MapLongPressEvent(_mapId, position)); + } + } catch (e) { + debugPrint('JavaScript Error: $e'); + } } - JavascriptChannel _onMarkerClick() { - return JavascriptChannel( - name: 'MarkerClick', - onMessageReceived: (JavascriptMessage message) async { - if (_widget == null) { - return; - } - try { - final dynamic id = json.decode(message.message); - if (_markersController != null && id is int) { - final MarkerId? markerId = _markersController!._idToMarkerId[id]; - final MarkerController? marker = - _markersController!._markerIdToController[markerId]; - if (marker?.tapEvent != null) { - marker?.tapEvent!(); - } - } - } catch (e) { - debugPrint('Javascript Error: $e'); - } - }); + void _onMarkerClick(JavaScriptMessage message) { + try { + final dynamic id = json.decode(message.message); + if (_markersController != null && id is int) { + final MarkerId? markerId = _markersController!._idToMarkerId[id]; + final MarkerController? marker = + _markersController!._markerIdToController[markerId]; + if (marker?.tapEvent != null) { + marker?.tapEvent!(); + } + } + } catch (e) { + debugPrint('JavaScript Error: $e'); + } } - JavascriptChannel _onMarkerDragEnd() { - return JavascriptChannel( - name: 'MarkerDragEnd', - onMessageReceived: (JavascriptMessage message) async { - if (_widget == null) { - return; - } - try { - final dynamic result = json.decode(message.message); - if (result is Map) { - assert(result['id'] != null && result['event'] != null); - if (_markersController != null && result['id'] is int) { - final MarkerId? markerId = - _markersController!._idToMarkerId[result['id']]; - final MarkerController? marker = - _markersController!._markerIdToController[markerId]; - - final LatLng position = LatLng( - result['event']['latLng']['lat'] as double, - result['event']['latLng']['lng'] as double); - - if (marker?.dragEndEvent != null) { - marker?.dragEndEvent!(position); - } - } - } - } catch (e) { - debugPrint('Javascript Error: $e'); + void _onMarkerDragEnd(JavaScriptMessage message) { + try { + final dynamic result = json.decode(message.message); + if (result is Map) { + assert(result['id'] != null && result['event'] != null); + if (_markersController != null && result['id'] is int) { + final MarkerId? markerId = + _markersController!._idToMarkerId[result['id']]; + final MarkerController? marker = + _markersController!._markerIdToController[markerId]; + + final LatLng position = LatLng( + result['event']['latLng']['lat'] as double, + result['event']['latLng']['lng'] as double); + + if (marker?.dragEndEvent != null) { + marker?.dragEndEvent!(position); } - }); + } + } + } catch (e) { + debugPrint('JavaScript Error: $e'); + } } - JavascriptChannel _onPolylineClick() { - return JavascriptChannel( - name: 'PolylineClick', - onMessageReceived: (JavascriptMessage message) async { - if (_widget == null) { - return; - } - try { - final dynamic id = json.decode(message.message); - if (_polylinesController != null && id is int) { - final PolylineId? polylineId = - _polylinesController!._idToPolylineId[id]; - final PolylineController? polyline = - _polylinesController!._polylineIdToController[polylineId]; - if (polyline?.tapEvent != null) { - polyline?.tapEvent!(); - } - } - } catch (e) { - debugPrint('Javascript Error: $e'); - } - }); + void _onPolylineClick(JavaScriptMessage message) { + try { + final dynamic id = json.decode(message.message); + if (_polylinesController != null && id is int) { + final PolylineId? polylineId = + _polylinesController!._idToPolylineId[id]; + final PolylineController? polyline = + _polylinesController!._polylineIdToController[polylineId]; + if (polyline?.tapEvent != null) { + polyline?.tapEvent!(); + } + } + } catch (e) { + debugPrint('JavaScript Error: $e'); + } } - JavascriptChannel _onPolygonClick() { - return JavascriptChannel( - name: 'PolygonClick', - onMessageReceived: (JavascriptMessage message) async { - if (_widget == null) { - return; - } - try { - final dynamic id = json.decode(message.message); - if (_polygonsController != null && id is int) { - final PolygonId? polygonId = - _polygonsController!._idToPolygonId[id]; - final PolygonController? polygon = - _polygonsController!._polygonIdToController[polygonId]; - if (polygon?.tapEvent != null) { - polygon?.tapEvent!(); - } - } - } catch (e) { - debugPrint('Javascript Error: $e'); - } - }); + void _onPolygonClick(JavaScriptMessage message) { + try { + final dynamic id = json.decode(message.message); + if (_polygonsController != null && id is int) { + final PolygonId? polygonId = _polygonsController!._idToPolygonId[id]; + final PolygonController? polygon = + _polygonsController!._polygonIdToController[polygonId]; + if (polygon?.tapEvent != null) { + polygon?.tapEvent!(); + } + } + } catch (e) { + debugPrint('JavaScript Error: $e'); + } } - JavascriptChannel _onCircleClick() { - return JavascriptChannel( - name: 'CircleClick', - onMessageReceived: (JavascriptMessage message) async { - if (_widget == null) { - return; - } - try { - final dynamic id = json.decode(message.message); - if (_polygonsController != null && id is int) { - final CircleId? circleId = _circlesController!._idToCircleId[id]; - final CircleController? circle = - _circlesController!._circleIdToController[circleId]; - if (circle?.tapEvent != null) { - circle?.tapEvent!(); - } - } - } catch (e) { - debugPrint('Javascript Error: $e'); - } - }); + void _onCircleClick(JavaScriptMessage message) { + try { + final dynamic id = json.decode(message.message); + if (_polygonsController != null && id is int) { + final CircleId? circleId = _circlesController!._idToCircleId[id]; + final CircleController? circle = + _circlesController!._circleIdToController[circleId]; + if (circle?.tapEvent != null) { + circle?.tapEvent!(); + } + } + } catch (e) { + debugPrint('JavaScript Error: $e'); + } } /// Initializes the map from the stored `rawOptions`. @@ -411,23 +360,24 @@ class GoogleMapsController { /// /// Failure to call this method would result in not rendering at all, /// and most of the public methods on this class no-op'ing. - void init() { - if (_widget == null && !_streamController.isClosed) { + Future init() async { + if (_webview == null && !_streamController.isClosed) { _getWebview(); - _createMap(); + await _pageFinishedCompleter.future; + await _createMap(); } - _attachGeometryControllers(); + await _attachGeometryControllers(); _renderInitialGeometry( markers: _markers, circles: _circles, polygons: _polygons, polylines: _polylines, ); - _setTrafficLayer(_isTrafficLayerEnabled(_rawMapOptions)); + await _setTrafficLayer(_isTrafficLayerEnabled(_rawMapOptions)); } // Binds the Geometry controllers to a map instance - void _attachGeometryControllers() { + Future _attachGeometryControllers() async { // Now we can add the initial geometry. // And bind the (ready) map instance to the other geometry controllers. assert(_circlesController != null, @@ -438,10 +388,10 @@ class GoogleMapsController { 'Cannot attach a map to a null PolylinesController instance.'); assert(_markersController != null, 'Cannot attach a map to a null MarkersController instance.'); - _circlesController!.bindToMap(_mapId, _widget!); - _polygonsController!.bindToMap(_mapId, _widget!); - _polylinesController!.bindToMap(_mapId, _widget!); - _markersController!.bindToMap(_mapId, _widget!); + _circlesController!.bindToMap(_mapId, _webview!); + _polygonsController!.bindToMap(_mapId, _webview!); + _polylinesController!.bindToMap(_mapId, _webview!); + _markersController!.bindToMap(_mapId, _webview!); util.webController = controller; _controllersBoundToMap = true; } @@ -481,7 +431,7 @@ class GoogleMapsController { /// /// This method converts the map into the proper [MapOptions] void updateRawOptions(Map optionsUpdate) { - assert(_widget != null, 'Cannot update options on a null map.'); + assert(_webview != null, 'Cannot update options on a null map.'); final Map newOptions = _mergeRawOptions(optionsUpdate); final String options = _rawOptionsToString(newOptions); @@ -491,13 +441,11 @@ class GoogleMapsController { } Future _setOptions(String options) async { - if (_controller.isCompleted) { - await _callMethod(await controller, 'setOptions', [options]); - } + await _callMethod(controller, 'setOptions', [options]); } Future _setZoom(String options) async { - await _callMethod(await controller, 'setZoom', [options]); + await _callMethod(controller, 'setZoom', [options]); } // Attaches/detaches a Traffic Layer on the `map` if `attach` is true/false. @@ -515,36 +463,36 @@ class GoogleMapsController { console.log('trafficLayer detached!!'); } '''; - await (await controller).runJavascript(command); + await controller.runJavaScript(command); } Future _setMoveCamera(String options) async { - await _callMethod(await controller, 'moveCamera', [options]); + await _callMethod(controller, 'moveCamera', [options]); } Future _setPanTo(String options) async { - await _callMethod(await controller, 'panTo', [options]); + await _callMethod(controller, 'panTo', [options]); } Future _setPanBy(String options) async { - await _callMethod(await controller, 'panBy', [options]); + await _callMethod(controller, 'panBy', [options]); } Future _setFitBounds(String options) async { - await _callMethod(await controller, 'fitBounds', [options]); + await _callMethod(controller, 'fitBounds', [options]); } - Future _callMethod( - WebViewController mapView, String method, List args) async { - return mapView.runJavascriptReturningResult( + Future _callMethod( + WebViewController controller, String method, List args) async { + return controller.runJavaScriptReturningResult( 'JSON.stringify(map.$method.apply(map, $args))'); } - Future _getZoom(WebViewController c) async { + Future _getZoom(WebViewController controller) async { try { - return double.parse(await _callMethod(c, 'getZoom', [])); + return await _callMethod(controller, 'getZoom', []) as num; } catch (e) { - debugPrint('Javascript Error: $e'); + debugPrint('JavaScript Error: $e'); return 0.0; } } @@ -552,13 +500,13 @@ class GoogleMapsController { /// Returns the [LatLngBounds] of the current viewport. Future getVisibleRegion() async { return _convertToBounds( - await _callMethod(await controller, 'getBounds', [])); + await _callMethod(controller, 'getBounds', []) as String); } /// Returns the [LatLng] at the center of the map. Future getCenter() async { return _convertToLatLng( - await _callMethod(await controller, 'getCenter', [])); + await _callMethod(controller, 'getCenter', []) as String); } /// Returns the [ScreenCoordinate] for a given viewport [LatLng]. @@ -644,7 +592,7 @@ class GoogleMapsController { JSON.stringify(getPixelToLatLng()); '''; - return (await controller).runJavascriptReturningResult(command); + return controller.runJavaScriptReturningResult(command) as String; } Future _latLngToPoint(LatLng latLng) async { @@ -664,12 +612,12 @@ class GoogleMapsController { JSON.stringify(getLatLngToPixel()); '''; - return (await controller).runJavascriptReturningResult(command); + return controller.runJavaScriptReturningResult(command) as String; } /// Returns the zoom level of the current viewport. - Future getZoomLevel() async { - return _getZoom(await controller); + Future getZoomLevel() async { + return _getZoom(controller); } // Geometry manipulation @@ -736,7 +684,7 @@ class GoogleMapsController { /// You won't be able to call many of the methods on this controller after /// calling `dispose`! void dispose() { - _widget = null; + _webview = null; _circlesController = null; _polygonsController = null; _polylinesController = null; diff --git a/packages/google_maps_flutter/lib/src/google_maps_flutter_tizen.dart b/packages/google_maps_flutter/lib/src/google_maps_flutter_tizen.dart index 32f6f1078..406aee8a1 100644 --- a/packages/google_maps_flutter/lib/src/google_maps_flutter_tizen.dart +++ b/packages/google_maps_flutter/lib/src/google_maps_flutter_tizen.dart @@ -42,7 +42,7 @@ class GoogleMapsPlugin extends GoogleMapsFlutterPlatform { @override Future init(int mapId) async { - _map(mapId).init(); + await _map(mapId).init(); } /// Updates the options of a given `mapId`. @@ -213,7 +213,7 @@ class GoogleMapsPlugin extends GoogleMapsFlutterPlatform { Future getZoomLevel({ required int mapId, }) { - return _map(mapId).getZoomLevel(); + return _map(mapId).getZoomLevel() as Future; } // The following are the 11 possible streams of data from the native side @@ -306,8 +306,8 @@ class GoogleMapsPlugin extends GoogleMapsFlutterPlatform { Map mapOptions = const {}, }) { // Bail fast if we've already rendered this map ID... - if (_mapById[creationId]?.widget != null) { - return _mapById[creationId]!.widget!; + if (_mapById[creationId]?.webview != null) { + return _mapById[creationId]!.webview!; } final StreamController> controller = @@ -335,10 +335,9 @@ class GoogleMapsPlugin extends GoogleMapsFlutterPlatform { // Notify the plugin now that there's a fully initialized controller. onPlatformViewCreated.call(event.mapId); }); - - assert(mapController.widget != null, + assert(mapController.webview != null, 'The widget of a GoogleMapsController cannot be null before calling dispose on it.'); - return mapController.widget!; + return mapController.webview!; } } diff --git a/packages/google_maps_flutter/lib/src/marker.dart b/packages/google_maps_flutter/lib/src/marker.dart index 9b234f4ec..63e25b22b 100644 --- a/packages/google_maps_flutter/lib/src/marker.dart +++ b/packages/google_maps_flutter/lib/src/marker.dart @@ -18,7 +18,7 @@ class MarkerController { bool consumeTapEvents = false, LatLngCallback? onDragEnd, ui.VoidCallback? onTap, - Future? controller, + WebViewController? controller, }) : _marker = marker, _infoWindow = infoWindow, _consumeTapEvents = consumeTapEvents, @@ -40,11 +40,11 @@ class MarkerController { /// Marker component's drag end event. LatLngCallback? dragEndEvent; - Future _addMarkerEvent(Future? controller) async { + Future _addMarkerEvent(WebViewController? controller) async { final String command = ''' $marker.addListener("click", (event) => MarkerClick.postMessage(JSON.stringify(${marker?.id}))); $marker.addListener("dragend", (event) => MarkerDragEnd.postMessage(JSON.stringify({id:${marker?.id}, event:event})));'''; - await (await controller!).runJavascript(command); + await controller!.runJavaScript(command); } /// Returns `true` if this Controller will use its own `onTap` handler to consume events. diff --git a/packages/google_maps_flutter/lib/src/polygon.dart b/packages/google_maps_flutter/lib/src/polygon.dart index e8da652bc..e15d70e43 100644 --- a/packages/google_maps_flutter/lib/src/polygon.dart +++ b/packages/google_maps_flutter/lib/src/polygon.dart @@ -12,7 +12,7 @@ class PolygonController { required util.GPolygon polygon, bool consumeTapEvents = false, ui.VoidCallback? onTap, - Future? controller, + WebViewController? controller, }) : _polygon = polygon, _consumeTapEvents = consumeTapEvents, tapEvent = onTap { @@ -25,10 +25,10 @@ class PolygonController { /// Polygon component's tap event. ui.VoidCallback? tapEvent; - Future _addPolygonEvent(Future? controller) async { + Future _addPolygonEvent(WebViewController? controller) async { final String command = "$_polygon.addListener('click', (event) => PolygonClick.postMessage(JSON.stringify(${_polygon?.id})));"; - await (await controller!).runJavascript(command); + await controller!.runJavaScript(command); } /// Returns `true` if this Controller will use its own `onTap` handler to consume events. diff --git a/packages/google_maps_flutter/lib/src/polyline.dart b/packages/google_maps_flutter/lib/src/polyline.dart index 735d27dc6..d5e1b0adf 100644 --- a/packages/google_maps_flutter/lib/src/polyline.dart +++ b/packages/google_maps_flutter/lib/src/polyline.dart @@ -12,7 +12,7 @@ class PolylineController { required util.GPolyline polyline, bool consumeTapEvents = false, ui.VoidCallback? onTap, - Future? controller, + WebViewController? controller, }) : _polyline = polyline, _consumeTapEvents = consumeTapEvents, tapEvent = onTap { @@ -25,10 +25,10 @@ class PolylineController { /// Polyline component's tap event. ui.VoidCallback? tapEvent; - Future _addPolylineEvent(Future? controller) async { + Future _addPolylineEvent(WebViewController? controller) async { final String command = "$_polyline.addListener('click', (event) => PolylineClick.postMessage(JSON.stringify(${_polyline?.id})));"; - await (await controller!).runJavascript(command); + await controller!.runJavaScript(command); } /// Returns `true` if this Controller will use its own `onTap` handler to consume events. diff --git a/packages/google_maps_flutter/lib/src/types.dart b/packages/google_maps_flutter/lib/src/types.dart index d2c6297ec..507bcd1be 100644 --- a/packages/google_maps_flutter/lib/src/types.dart +++ b/packages/google_maps_flutter/lib/src/types.dart @@ -17,13 +17,13 @@ typedef LatLngCallback = void Function(LatLng latLng); /// instance and our internal `mapId` value. abstract class GeometryController { /// The WebView instance that this controller operates on. - late WebView webview; + late WebViewWidget webview; /// The map ID for events. late int mapId; /// Binds a `mapId` and the map instance to this controller. - void bindToMap(int mapId, WebView webview) { + void bindToMap(int mapId, WebViewWidget webview) { this.mapId = mapId; this.webview = webview; } diff --git a/packages/google_maps_flutter/lib/src/util.dart b/packages/google_maps_flutter/lib/src/util.dart index bf8b7dedc..83b089d22 100644 --- a/packages/google_maps_flutter/lib/src/util.dart +++ b/packages/google_maps_flutter/lib/src/util.dart @@ -160,7 +160,7 @@ class GInfoWindow { } Future _createInfoWindow(GInfoWindowOptions? opts) async { - await (await webController!).runJavascript( + await webController!.runJavaScript( 'var ${toString()} = new google.maps.InfoWindow($opts);'); } @@ -173,7 +173,7 @@ class GInfoWindow { } Future _callCloseInfoWindow() async { - await (await webController!).runJavascript('${toString()}.close();'); + await webController!.runJavaScript('${toString()}.close();'); } /// Opens InfoWindow on the given map. @@ -184,8 +184,8 @@ class GInfoWindow { } Future _callOpenInfoWindow(GMarker? anchor) async { - await (await webController!) - .runJavascript('${toString()}.open({anchor: $anchor, map});'); + await webController! + .runJavaScript('${toString()}.open({anchor: $anchor, map});'); } @override @@ -199,12 +199,12 @@ class GInfoWindow { /// Sets the offset of the tip of the info window from the point on the map. set pixelOffset(GSize? size) => _setPixelOffset(size); - void _setContent(Object? /*String?|Node?*/ content) { - callMethod(this, 'setContent', [content]); + Future _setContent(Object? /*String?|Node?*/ content) async { + await callMethod(this, 'setContent', [content]); } - void _setPixelOffset(GSize? size) { - setProperty(this, 'pixelOffset', size?.toValue()); + Future _setPixelOffset(GSize? size) async { + await setProperty(this, 'pixelOffset', size?.toValue()); } } @@ -219,8 +219,8 @@ class GMarker { } Future _createMarker(GMarkerOptions? opts) async { - await (await webController!) - .runJavascript('var ${toString()} = new google.maps.Marker($opts);'); + await webController! + .runJavaScript('var ${toString()} = new google.maps.Marker($opts);'); } /// GMarker id. @@ -271,8 +271,8 @@ class GPolyline { } Future _createPolyline(GPolylineOptions? opts) async { - await (await webController!) - .runJavascript('var ${toString()} = new google.maps.Polyline($opts);'); + await webController! + .runJavaScript('var ${toString()} = new google.maps.Polyline($opts);'); } /// GPolyline id. @@ -365,8 +365,8 @@ class GPolygon { } Future _createPolygon(GPolygonOptions? opts) async { - await (await webController!) - .runJavascript('var ${toString()} = new google.maps.Polygon($opts);'); + await webController! + .runJavaScript('var ${toString()} = new google.maps.Polygon($opts);'); } /// GPolygon id. @@ -469,8 +469,8 @@ class GCircle { } Future _createCircle(GCircleOptions? opts) async { - await (await webController!) - .runJavascript('var ${toString()} = new google.maps.Circle($opts);'); + await webController! + .runJavaScript('var ${toString()} = new google.maps.Circle($opts);'); } /// GCircle id. @@ -558,25 +558,16 @@ class GCircleOptions { } /// Returns webview controller instance -Future? webController; - -/// Returns the property value of the object. -Future getProperty(Object o, String property) async { - assert(webController != null, 'mapController is null!!'); - final String command = "JSON.stringify($o['$property'])"; - return (await webController!).runJavascriptReturningResult(command); -} +WebViewController? webController; /// Sets the value to property of the object. -Future setProperty(Object o, String property, Object? value) async { - assert(webController != null, 'mapController is null!!'); +Future setProperty(Object o, String property, Object? value) async { final String command = "JSON.stringify($o['$property'] = $value)"; - return (await webController!).runJavascriptReturningResult(command); + await webController!.runJavaScript(command); } /// Calls the method of the object with the args. -Future callMethod(Object o, String method, List args) async { - assert(webController != null, 'webController is null!!'); +Future callMethod(Object o, String method, List args) async { final String command = 'JSON.stringify($o.$method.apply($o, $args))'; - return (await webController!).runJavascriptReturningResult(command); + await webController!.runJavaScript(command); } diff --git a/packages/google_maps_flutter/pubspec.yaml b/packages/google_maps_flutter/pubspec.yaml index 6df59323c..7daeb204e 100644 --- a/packages/google_maps_flutter/pubspec.yaml +++ b/packages/google_maps_flutter/pubspec.yaml @@ -2,7 +2,7 @@ name: google_maps_flutter_tizen description: Tizen implementation of the google_maps_flutter plugin. homepage: https://github.com/flutter-tizen/plugins repository: https://github.com/flutter-tizen/plugins/tree/master/packages/google_maps_flutter -version: 0.1.5 +version: 0.1.6 environment: sdk: ">=3.1.0 <4.0.0" @@ -19,5 +19,5 @@ dependencies: sdk: flutter google_maps_flutter_platform_interface: ^2.1.2 stream_transform: ^2.0.0 - webview_flutter: ^3.0.4 - webview_flutter_lwe: ^0.1.0 + webview_flutter: ^4.4.2 + webview_flutter_lwe: ^0.3.0