From b17d1dc99bd45f00ca920c3f8b85900bffc1c4e5 Mon Sep 17 00:00:00 2001 From: Maurice Parrish Date: Wed, 16 Jun 2021 17:52:01 -0700 Subject: [PATCH 01/12] start --- .../lib/src/google_map.dart | 26 +++++++++++++++- .../google_maps_flutter/pubspec.yaml | 5 ++- .../test/google_map_test.dart | 31 +++++++++++-------- 3 files changed, 47 insertions(+), 15 deletions(-) diff --git a/packages/google_maps_flutter/google_maps_flutter/lib/src/google_map.dart b/packages/google_maps_flutter/google_maps_flutter/lib/src/google_map.dart index 26b9d6b83c84..294a131e09e1 100644 --- a/packages/google_maps_flutter/google_maps_flutter/lib/src/google_map.dart +++ b/packages/google_maps_flutter/google_maps_flutter/lib/src/google_map.dart @@ -61,6 +61,7 @@ class GoogleMap extends StatefulWidget { this.tiltGesturesEnabled = true, this.myLocationEnabled = false, this.myLocationButtonEnabled = true, + this.textDirection, /// If no padding is specified default padding will be 0. this.padding = const EdgeInsets.all(0), @@ -100,6 +101,13 @@ class GoogleMap extends StatefulWidget { /// Type of map tiles to be rendered. final MapType mapType; + /// {@template flutter.widgets.AndroidView.layoutDirection} + /// The text direction to use for the embedded view. + /// + /// If this is null, the ambient [Directionality] is used instead. + /// {@endtemplate} + final TextDirection? textDirection; + /// Preferred bounds for the camera zoom level. /// /// Actual bounds depend on map data and device. @@ -250,7 +258,23 @@ class _GoogleMapState extends State { @override Widget build(BuildContext context) { - return GoogleMapsFlutterPlatform.instance.buildView( + final GoogleMapsFlutterPlatform platform = + GoogleMapsFlutterPlatform.instance; + if (platform is MethodChannelGoogleMapsFlutter) { + return platform.buildViewWithTextDirection( + _mapId, + onPlatformViewCreated, + textDirection: widget.textDirection ?? Directionality.of(context), + initialCameraPosition: widget.initialCameraPosition, + markers: widget.markers, + polygons: widget.polygons, + polylines: widget.polylines, + circles: widget.circles, + gestureRecognizers: widget.gestureRecognizers, + mapOptions: _googleMapOptions.toMap(), + ); + } + return platform.buildView( _mapId, onPlatformViewCreated, initialCameraPosition: widget.initialCameraPosition, diff --git a/packages/google_maps_flutter/google_maps_flutter/pubspec.yaml b/packages/google_maps_flutter/google_maps_flutter/pubspec.yaml index 0d7475857b31..7fa9abbe34d5 100644 --- a/packages/google_maps_flutter/google_maps_flutter/pubspec.yaml +++ b/packages/google_maps_flutter/google_maps_flutter/pubspec.yaml @@ -21,7 +21,10 @@ dependencies: flutter: sdk: flutter flutter_plugin_android_lifecycle: ^2.0.1 - google_maps_flutter_platform_interface: ^2.0.0 + google_maps_flutter_platform_interface: + git: + url: git@github.com:flutter/plugins.git + path: packages/google_maps_flutter/google_maps_flutter_platform_interface dev_dependencies: flutter_test: diff --git a/packages/google_maps_flutter/google_maps_flutter/test/google_map_test.dart b/packages/google_maps_flutter/google_maps_flutter/test/google_map_test.dart index d1ec87a4730d..003ae06d9877 100644 --- a/packages/google_maps_flutter/google_maps_flutter/test/google_map_test.dart +++ b/packages/google_maps_flutter/google_maps_flutter/test/google_map_test.dart @@ -6,6 +6,7 @@ import 'package:flutter/services.dart'; import 'package:flutter/widgets.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:google_maps_flutter/google_maps_flutter.dart'; +import 'package:google_maps_flutter_platform_interface/google_maps_flutter_platform_interface.dart'; import 'fake_maps_controllers.dart'; @@ -604,17 +605,21 @@ void main() { }, ); - // TODO(bparrishMines): Uncomment once https://github.com/flutter/plugins/pull/4017 has landed. - // testWidgets('Use AndroidViewSurface on Android', (WidgetTester tester) async { - // await tester.pumpWidget( - // const Directionality( - // textDirection: TextDirection.ltr, - // child: GoogleMap( - // initialCameraPosition: CameraPosition(target: LatLng(10.0, 15.0)), - // ), - // ), - // ); - // - // expect(find.byType(AndroidViewSurface), findsOneWidget); - // }); + testWidgets('Use PlatformViewLink on Android', (WidgetTester tester) async { + final MethodChannelGoogleMapsFlutter platform = + GoogleMapsFlutterPlatform.instance as MethodChannelGoogleMapsFlutter; + platform.useAndroidViewSurface = true; + + await tester.pumpWidget( + const Directionality( + textDirection: TextDirection.ltr, + child: GoogleMap( + initialCameraPosition: CameraPosition(target: LatLng(10.0, 15.0)), + ), + ), + ); + + expect(find.byType(PlatformViewLink), findsOneWidget); + platform.useAndroidViewSurface = false; + }); } From 82c46146652f3433bd74bb355d1c6392cb648b9a Mon Sep 17 00:00:00 2001 From: Maurice Parrish Date: Thu, 17 Jun 2021 13:34:25 -0700 Subject: [PATCH 02/12] change to hybrid composition in example --- .../google_maps_flutter/google_maps_flutter/CHANGELOG.md | 3 ++- .../google_maps_flutter/example/lib/main.dart | 8 ++++++++ .../google_maps_flutter/lib/google_maps_flutter.dart | 2 ++ .../google_maps_flutter/google_maps_flutter/pubspec.yaml | 7 ++----- 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/packages/google_maps_flutter/google_maps_flutter/CHANGELOG.md b/packages/google_maps_flutter/google_maps_flutter/CHANGELOG.md index 5ba399311661..d48a3219ca08 100644 --- a/packages/google_maps_flutter/google_maps_flutter/CHANGELOG.md +++ b/packages/google_maps_flutter/google_maps_flutter/CHANGELOG.md @@ -1,6 +1,7 @@ -## NEXT +## 2.1.0 * Add iOS unit and UI integration test targets. +* Provide access to Hybrid Composition on Android through the `GoogleMap` widget. ## 2.0.6 diff --git a/packages/google_maps_flutter/google_maps_flutter/example/lib/main.dart b/packages/google_maps_flutter/google_maps_flutter/example/lib/main.dart index 15b14db0357a..2d00c5e968b2 100644 --- a/packages/google_maps_flutter/google_maps_flutter/example/lib/main.dart +++ b/packages/google_maps_flutter/google_maps_flutter/example/lib/main.dart @@ -4,7 +4,9 @@ // ignore_for_file: public_member_api_docs +import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; +import 'package:google_maps_flutter/google_maps_flutter.dart'; import 'package:google_maps_flutter_example/lite_mode.dart'; import 'animate_camera.dart'; import 'map_click.dart'; @@ -66,5 +68,11 @@ class MapsDemo extends StatelessWidget { } void main() { + WidgetsFlutterBinding.ensureInitialized(); + if (defaultTargetPlatform == TargetPlatform.android) { + final MethodChannelGoogleMapsFlutter platform = + GoogleMapsFlutterPlatform.instance as MethodChannelGoogleMapsFlutter; + platform.useAndroidViewSurface; + } runApp(MaterialApp(home: MapsDemo())); } diff --git a/packages/google_maps_flutter/google_maps_flutter/lib/google_maps_flutter.dart b/packages/google_maps_flutter/google_maps_flutter/lib/google_maps_flutter.dart index 93bb0566dd1f..374cf3a7698b 100644 --- a/packages/google_maps_flutter/google_maps_flutter/lib/google_maps_flutter.dart +++ b/packages/google_maps_flutter/google_maps_flutter/lib/google_maps_flutter.dart @@ -28,6 +28,7 @@ export 'package:google_maps_flutter_platform_interface/google_maps_flutter_platf Cap, Circle, CircleId, + GoogleMapsFlutterPlatform, InfoWindow, JointType, LatLng, @@ -36,6 +37,7 @@ export 'package:google_maps_flutter_platform_interface/google_maps_flutter_platf MapType, Marker, MarkerId, + MethodChannelGoogleMapsFlutter, MinMaxZoomPreference, PatternItem, Polygon, diff --git a/packages/google_maps_flutter/google_maps_flutter/pubspec.yaml b/packages/google_maps_flutter/google_maps_flutter/pubspec.yaml index 7fa9abbe34d5..04c474643dfd 100644 --- a/packages/google_maps_flutter/google_maps_flutter/pubspec.yaml +++ b/packages/google_maps_flutter/google_maps_flutter/pubspec.yaml @@ -2,7 +2,7 @@ name: google_maps_flutter description: A Flutter plugin for integrating Google Maps in iOS and Android applications. repository: https://github.com/flutter/plugins/tree/master/packages/google_maps_flutter/google_maps_flutter issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+maps%22 -version: 2.0.6 +version: 2.1.0 environment: sdk: '>=2.12.0 <3.0.0' @@ -21,10 +21,7 @@ dependencies: flutter: sdk: flutter flutter_plugin_android_lifecycle: ^2.0.1 - google_maps_flutter_platform_interface: - git: - url: git@github.com:flutter/plugins.git - path: packages/google_maps_flutter/google_maps_flutter_platform_interface + google_maps_flutter_platform_interface: ^2.1.0 dev_dependencies: flutter_test: From 7b6f8019473e4b48f24f8ce8f33f0427fd982a73 Mon Sep 17 00:00:00 2001 From: Maurice Parrish Date: Thu, 17 Jun 2021 13:39:52 -0700 Subject: [PATCH 03/12] UPdate readme --- .../google_maps_flutter/README.md | 13 +++++++++++++ .../google_maps_flutter/example/lib/main.dart | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/packages/google_maps_flutter/google_maps_flutter/README.md b/packages/google_maps_flutter/google_maps_flutter/README.md index c80fcb949dad..ed56b5da58ea 100644 --- a/packages/google_maps_flutter/google_maps_flutter/README.md +++ b/packages/google_maps_flutter/google_maps_flutter/README.md @@ -46,6 +46,19 @@ This means that app will only be available for users that run Android SDK 20 or android:value="YOUR KEY HERE"/> ``` +#### Hybrid Composition + +To use Hybrid Composition to render the `GoogleMap` widget on Android. Set the +`MethodChannelGoogleMapsFlutter.useAndroidViewSurface` to true. + +```dart +if (defaultTargetPlatform == TargetPlatform.android) { + final MethodChannelGoogleMapsFlutter platform = + GoogleMapsFlutterPlatform.instance as MethodChannelGoogleMapsFlutter; + platform.useAndroidViewSurface = true; +} +``` + ### iOS Specify your API key in the application delegate `ios/Runner/AppDelegate.m`: diff --git a/packages/google_maps_flutter/google_maps_flutter/example/lib/main.dart b/packages/google_maps_flutter/google_maps_flutter/example/lib/main.dart index 2d00c5e968b2..321a92054f6f 100644 --- a/packages/google_maps_flutter/google_maps_flutter/example/lib/main.dart +++ b/packages/google_maps_flutter/google_maps_flutter/example/lib/main.dart @@ -72,7 +72,7 @@ void main() { if (defaultTargetPlatform == TargetPlatform.android) { final MethodChannelGoogleMapsFlutter platform = GoogleMapsFlutterPlatform.instance as MethodChannelGoogleMapsFlutter; - platform.useAndroidViewSurface; + platform.useAndroidViewSurface = true; } runApp(MaterialApp(home: MapsDemo())); } From f6631b4b4e136d8f7ab1d0d02e9d2baafba4002a Mon Sep 17 00:00:00 2001 From: Maurice Parrish Date: Tue, 29 Jun 2021 14:54:17 -0700 Subject: [PATCH 04/12] update README and remove unnecessary line --- packages/google_maps_flutter/google_maps_flutter/README.md | 2 +- .../google_maps_flutter/example/lib/main.dart | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/google_maps_flutter/google_maps_flutter/README.md b/packages/google_maps_flutter/google_maps_flutter/README.md index ed56b5da58ea..0bf2b378968c 100644 --- a/packages/google_maps_flutter/google_maps_flutter/README.md +++ b/packages/google_maps_flutter/google_maps_flutter/README.md @@ -48,7 +48,7 @@ This means that app will only be available for users that run Android SDK 20 or #### Hybrid Composition -To use Hybrid Composition to render the `GoogleMap` widget on Android. Set the +To use [Hybrid Composition](https://flutter.dev/docs/development/platform-integration/platform-views) to render the `GoogleMap` widget on Android. Set `MethodChannelGoogleMapsFlutter.useAndroidViewSurface` to true. ```dart diff --git a/packages/google_maps_flutter/google_maps_flutter/example/lib/main.dart b/packages/google_maps_flutter/google_maps_flutter/example/lib/main.dart index 321a92054f6f..acadd355e4d9 100644 --- a/packages/google_maps_flutter/google_maps_flutter/example/lib/main.dart +++ b/packages/google_maps_flutter/google_maps_flutter/example/lib/main.dart @@ -68,7 +68,6 @@ class MapsDemo extends StatelessWidget { } void main() { - WidgetsFlutterBinding.ensureInitialized(); if (defaultTargetPlatform == TargetPlatform.android) { final MethodChannelGoogleMapsFlutter platform = GoogleMapsFlutterPlatform.instance as MethodChannelGoogleMapsFlutter; From 944d965b496f0f6ce38d2b923d339b44abd980e0 Mon Sep 17 00:00:00 2001 From: Maurice Parrish Date: Thu, 12 Aug 2021 11:16:15 -0700 Subject: [PATCH 05/12] use buildViewWithTextDirection by default --- .../lib/src/google_map.dart | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) diff --git a/packages/google_maps_flutter/google_maps_flutter/lib/src/google_map.dart b/packages/google_maps_flutter/google_maps_flutter/lib/src/google_map.dart index 294a131e09e1..aaa0b3772ade 100644 --- a/packages/google_maps_flutter/google_maps_flutter/lib/src/google_map.dart +++ b/packages/google_maps_flutter/google_maps_flutter/lib/src/google_map.dart @@ -258,25 +258,10 @@ class _GoogleMapState extends State { @override Widget build(BuildContext context) { - final GoogleMapsFlutterPlatform platform = - GoogleMapsFlutterPlatform.instance; - if (platform is MethodChannelGoogleMapsFlutter) { - return platform.buildViewWithTextDirection( - _mapId, - onPlatformViewCreated, - textDirection: widget.textDirection ?? Directionality.of(context), - initialCameraPosition: widget.initialCameraPosition, - markers: widget.markers, - polygons: widget.polygons, - polylines: widget.polylines, - circles: widget.circles, - gestureRecognizers: widget.gestureRecognizers, - mapOptions: _googleMapOptions.toMap(), - ); - } - return platform.buildView( + return GoogleMapsFlutterPlatform.instance.buildViewWithTextDirection( _mapId, onPlatformViewCreated, + textDirection: widget.textDirection ?? Directionality.of(context), initialCameraPosition: widget.initialCameraPosition, markers: widget.markers, polygons: widget.polygons, From e345f3a3fe4ddc6ee31b0f6fefe831eb3929e13c Mon Sep 17 00:00:00 2001 From: Maurice Parrish Date: Thu, 12 Aug 2021 11:17:42 -0700 Subject: [PATCH 06/12] remove hash --- packages/google_maps_flutter/google_maps_flutter/CHANGELOG.md | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/google_maps_flutter/google_maps_flutter/CHANGELOG.md b/packages/google_maps_flutter/google_maps_flutter/CHANGELOG.md index fbf73a251dd4..11c9ac4fe17d 100644 --- a/packages/google_maps_flutter/google_maps_flutter/CHANGELOG.md +++ b/packages/google_maps_flutter/google_maps_flutter/CHANGELOG.md @@ -12,7 +12,6 @@ * Add iOS unit and UI integration test targets. * Exclude arm64 simulators in example app. * Remove references to the Android V1 embedding. ->>>>>>> 4383bb15d91384efb22dbe409c3fd58e4552267c ## 2.0.6 From 1809e663fff2ce6ba8e4e48c66b46e2f926a05e1 Mon Sep 17 00:00:00 2001 From: Maurice Parrish Date: Thu, 12 Aug 2021 16:31:56 -0700 Subject: [PATCH 07/12] add default value if no directionality ancestor --- .../google_maps_flutter/lib/src/google_map.dart | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/google_maps_flutter/google_maps_flutter/lib/src/google_map.dart b/packages/google_maps_flutter/google_maps_flutter/lib/src/google_map.dart index aaa0b3772ade..f6c3470b760b 100644 --- a/packages/google_maps_flutter/google_maps_flutter/lib/src/google_map.dart +++ b/packages/google_maps_flutter/google_maps_flutter/lib/src/google_map.dart @@ -101,11 +101,11 @@ class GoogleMap extends StatefulWidget { /// Type of map tiles to be rendered. final MapType mapType; - /// {@template flutter.widgets.AndroidView.layoutDirection} + /// {@macro template_name} /// The text direction to use for the embedded view. /// - /// If this is null, the ambient [Directionality] is used instead. - /// {@endtemplate} + /// If this is null, the ambient [Directionality] is used instead. If there is + /// no ambient [Directionality], [TextDirection.ltr] is used. final TextDirection? textDirection; /// Preferred bounds for the camera zoom level. @@ -261,7 +261,9 @@ class _GoogleMapState extends State { return GoogleMapsFlutterPlatform.instance.buildViewWithTextDirection( _mapId, onPlatformViewCreated, - textDirection: widget.textDirection ?? Directionality.of(context), + textDirection: widget.textDirection ?? + Directionality.maybeOf(context) ?? + TextDirection.ltr, initialCameraPosition: widget.initialCameraPosition, markers: widget.markers, polygons: widget.polygons, From f504ffc597166c1edb1811ae9c83aab98fc6fc53 Mon Sep 17 00:00:00 2001 From: Maurice Parrish Date: Sun, 15 Aug 2021 13:39:06 -0700 Subject: [PATCH 08/12] remove mactro --- .../google_maps_flutter/lib/src/google_map.dart | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/google_maps_flutter/google_maps_flutter/lib/src/google_map.dart b/packages/google_maps_flutter/google_maps_flutter/lib/src/google_map.dart index f6c3470b760b..4430ea91f145 100644 --- a/packages/google_maps_flutter/google_maps_flutter/lib/src/google_map.dart +++ b/packages/google_maps_flutter/google_maps_flutter/lib/src/google_map.dart @@ -101,7 +101,6 @@ class GoogleMap extends StatefulWidget { /// Type of map tiles to be rendered. final MapType mapType; - /// {@macro template_name} /// The text direction to use for the embedded view. /// /// If this is null, the ambient [Directionality] is used instead. If there is From be87b94172a1ad4f434f748b71c6eba75f67b747 Mon Sep 17 00:00:00 2001 From: Maurice Parrish Date: Mon, 16 Aug 2021 22:58:27 -0700 Subject: [PATCH 09/12] change text direction to layout direction --- .../google_maps_flutter/lib/src/google_map.dart | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/google_maps_flutter/google_maps_flutter/lib/src/google_map.dart b/packages/google_maps_flutter/google_maps_flutter/lib/src/google_map.dart index 4430ea91f145..da61cf940b03 100644 --- a/packages/google_maps_flutter/google_maps_flutter/lib/src/google_map.dart +++ b/packages/google_maps_flutter/google_maps_flutter/lib/src/google_map.dart @@ -61,7 +61,7 @@ class GoogleMap extends StatefulWidget { this.tiltGesturesEnabled = true, this.myLocationEnabled = false, this.myLocationButtonEnabled = true, - this.textDirection, + this.layoutDirection, /// If no padding is specified default padding will be 0. this.padding = const EdgeInsets.all(0), @@ -101,11 +101,11 @@ class GoogleMap extends StatefulWidget { /// Type of map tiles to be rendered. final MapType mapType; - /// The text direction to use for the embedded view. + /// The layout direction to use for the embedded view. /// /// If this is null, the ambient [Directionality] is used instead. If there is /// no ambient [Directionality], [TextDirection.ltr] is used. - final TextDirection? textDirection; + final TextDirection? layoutDirection; /// Preferred bounds for the camera zoom level. /// @@ -260,7 +260,7 @@ class _GoogleMapState extends State { return GoogleMapsFlutterPlatform.instance.buildViewWithTextDirection( _mapId, onPlatformViewCreated, - textDirection: widget.textDirection ?? + textDirection: widget.layoutDirection ?? Directionality.maybeOf(context) ?? TextDirection.ltr, initialCameraPosition: widget.initialCameraPosition, From d90784525475b0f4fbcdb0bfbc4615ddc4b7eb3f Mon Sep 17 00:00:00 2001 From: Maurice Parrish Date: Mon, 23 Aug 2021 10:39:36 -0700 Subject: [PATCH 10/12] create android settings class --- .../google_maps_flutter/example/lib/main.dart | 4 +- .../lib/google_maps_flutter.dart | 2 - .../lib/src/google_map.dart | 42 +++++++++++++++++++ 3 files changed, 43 insertions(+), 5 deletions(-) diff --git a/packages/google_maps_flutter/google_maps_flutter/example/lib/main.dart b/packages/google_maps_flutter/google_maps_flutter/example/lib/main.dart index acadd355e4d9..5d933459825d 100644 --- a/packages/google_maps_flutter/google_maps_flutter/example/lib/main.dart +++ b/packages/google_maps_flutter/google_maps_flutter/example/lib/main.dart @@ -69,9 +69,7 @@ class MapsDemo extends StatelessWidget { void main() { if (defaultTargetPlatform == TargetPlatform.android) { - final MethodChannelGoogleMapsFlutter platform = - GoogleMapsFlutterPlatform.instance as MethodChannelGoogleMapsFlutter; - platform.useAndroidViewSurface = true; + AndroidGoogleMapsFlutter.useAndroidViewSurface = true; } runApp(MaterialApp(home: MapsDemo())); } diff --git a/packages/google_maps_flutter/google_maps_flutter/lib/google_maps_flutter.dart b/packages/google_maps_flutter/google_maps_flutter/lib/google_maps_flutter.dart index 374cf3a7698b..93bb0566dd1f 100644 --- a/packages/google_maps_flutter/google_maps_flutter/lib/google_maps_flutter.dart +++ b/packages/google_maps_flutter/google_maps_flutter/lib/google_maps_flutter.dart @@ -28,7 +28,6 @@ export 'package:google_maps_flutter_platform_interface/google_maps_flutter_platf Cap, Circle, CircleId, - GoogleMapsFlutterPlatform, InfoWindow, JointType, LatLng, @@ -37,7 +36,6 @@ export 'package:google_maps_flutter_platform_interface/google_maps_flutter_platf MapType, Marker, MarkerId, - MethodChannelGoogleMapsFlutter, MinMaxZoomPreference, PatternItem, Polygon, diff --git a/packages/google_maps_flutter/google_maps_flutter/lib/src/google_map.dart b/packages/google_maps_flutter/google_maps_flutter/lib/src/google_map.dart index da61cf940b03..4137dc1a470e 100644 --- a/packages/google_maps_flutter/google_maps_flutter/lib/src/google_map.dart +++ b/packages/google_maps_flutter/google_maps_flutter/lib/src/google_map.dart @@ -38,6 +38,48 @@ class UnknownMapObjectIdError extends Error { } } +/// Android specific settings for [GoogleMap]. +class AndroidGoogleMapsFlutter { + /// Whether to render [GoogleMap] with a [AndroidViewSurface] to build the Google Maps widget. + /// + /// This implementation uses hybrid composition to render the Google Maps + /// Widget on Android. This comes at the cost of some performance on Android + /// versions below 10. See + /// https://flutter.dev/docs/development/platform-integration/platform-views#performance for more + /// information. + /// + /// Defaults to false. + static bool get useAndroidViewSurface { + assert( + GoogleMapsFlutterPlatform.instance is MethodChannelGoogleMapsFlutter, + 'This feature is only supported when `GoogleMapsFlutterPlatform.instance` ' + 'is a `MethodChannelGoogleMapsFlutter`. The default implementation for Android.', + ); + return (GoogleMapsFlutterPlatform.instance + as MethodChannelGoogleMapsFlutter) + .useAndroidViewSurface; + } + + /// Set whether to render [GoogleMap] with a [AndroidViewSurface] to build the Google Maps widget. + /// + /// This implementation uses hybrid composition to render the Google Maps + /// Widget on Android. This comes at the cost of some performance on Android + /// versions below 10. See + /// https://flutter.dev/docs/development/platform-integration/platform-views#performance for more + /// information. + /// + /// Defaults to false. + static set useAndroidViewSurface(bool useAndroidViewSurface) { + assert( + GoogleMapsFlutterPlatform.instance is MethodChannelGoogleMapsFlutter, + 'This feature is only supported when `GoogleMapsFlutterPlatform.instance` ' + 'is a `MethodChannelGoogleMapsFlutter`. The default implementation for Android.', + ); + (GoogleMapsFlutterPlatform.instance as MethodChannelGoogleMapsFlutter) + .useAndroidViewSurface = useAndroidViewSurface; + } +} + /// A widget which displays a map with data obtained from the Google Maps service. class GoogleMap extends StatefulWidget { /// Creates a widget displaying data from Google Maps services. From 58c3028e70431250e7cbf3363e8384541aa9bf0e Mon Sep 17 00:00:00 2001 From: Maurice Parrish Date: Mon, 23 Aug 2021 10:42:26 -0700 Subject: [PATCH 11/12] update readme --- .../google_maps_flutter/google_maps_flutter/README.md | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/packages/google_maps_flutter/google_maps_flutter/README.md b/packages/google_maps_flutter/google_maps_flutter/README.md index 0bf2b378968c..347a8f48ebd4 100644 --- a/packages/google_maps_flutter/google_maps_flutter/README.md +++ b/packages/google_maps_flutter/google_maps_flutter/README.md @@ -48,14 +48,13 @@ This means that app will only be available for users that run Android SDK 20 or #### Hybrid Composition -To use [Hybrid Composition](https://flutter.dev/docs/development/platform-integration/platform-views) to render the `GoogleMap` widget on Android. Set -`MethodChannelGoogleMapsFlutter.useAndroidViewSurface` to true. +To use [Hybrid Composition](https://flutter.dev/docs/development/platform-integration/platform-views) +to render the `GoogleMap` widget on Android, set `AndroidGoogleMapsFlutter.useAndroidViewSurface` to +true. ```dart if (defaultTargetPlatform == TargetPlatform.android) { - final MethodChannelGoogleMapsFlutter platform = - GoogleMapsFlutterPlatform.instance as MethodChannelGoogleMapsFlutter; - platform.useAndroidViewSurface = true; + AndroidGoogleMapsFlutter.useAndroidViewSurface = true; } ``` From 0c26d6c5cbaeaebba984826708df10a8038e405e Mon Sep 17 00:00:00 2001 From: Maurice Parrish Date: Tue, 14 Sep 2021 10:49:23 -0700 Subject: [PATCH 12/12] Update google_map.dart --- .../google_maps_flutter/lib/src/google_map.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/google_maps_flutter/google_maps_flutter/lib/src/google_map.dart b/packages/google_maps_flutter/google_maps_flutter/lib/src/google_map.dart index 4137dc1a470e..7adc8ea56393 100644 --- a/packages/google_maps_flutter/google_maps_flutter/lib/src/google_map.dart +++ b/packages/google_maps_flutter/google_maps_flutter/lib/src/google_map.dart @@ -53,7 +53,7 @@ class AndroidGoogleMapsFlutter { assert( GoogleMapsFlutterPlatform.instance is MethodChannelGoogleMapsFlutter, 'This feature is only supported when `GoogleMapsFlutterPlatform.instance` ' - 'is a `MethodChannelGoogleMapsFlutter`. The default implementation for Android.', + 'is a `MethodChannelGoogleMapsFlutter`; The default implementation for Android.', ); return (GoogleMapsFlutterPlatform.instance as MethodChannelGoogleMapsFlutter) @@ -73,7 +73,7 @@ class AndroidGoogleMapsFlutter { assert( GoogleMapsFlutterPlatform.instance is MethodChannelGoogleMapsFlutter, 'This feature is only supported when `GoogleMapsFlutterPlatform.instance` ' - 'is a `MethodChannelGoogleMapsFlutter`. The default implementation for Android.', + 'is a `MethodChannelGoogleMapsFlutter`; The default implementation for Android.', ); (GoogleMapsFlutterPlatform.instance as MethodChannelGoogleMapsFlutter) .useAndroidViewSurface = useAndroidViewSurface;