-
Notifications
You must be signed in to change notification settings - Fork 9.7k
Support Hybrid Composition through the GoogleMaps Widget #4082
Changes from 4 commits
b17d1dc
82c4614
7b6f801
736c073
f6631b4
50b548e
944d965
e345f3a
1809e66
f504ffc
be87b94
cf87583
d907845
58c3028
0c26d6c
86f965c
35a8186
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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. | ||
bparrishMines marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ```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`: | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 = true; | ||
| } | ||
| runApp(MaterialApp(home: MapsDemo())); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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<GoogleMap> { | |
|
|
||
| @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, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: s/. Set the/, set/