Skip to content

Commit 7bcaa86

Browse files
committed
[google_maps_flutter] resolves merge conflicts with main
1 parent 135bf2b commit 7bcaa86

File tree

39 files changed

+702
-24
lines changed

39 files changed

+702
-24
lines changed

packages/flutter_migrate/test/apply_test.dart

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,7 @@ deleted_files:
143143
conflictFile.createSync(recursive: true);
144144
conflictFile.writeAsStringSync('''
145145
line1
146-
<<<<<<< /conflcit/conflict.file
147146
line2
148-
=======
149-
linetwo
150-
>>>>>>> /var/folders/md/gm0zgfcj07vcsj6jkh_mp_wh00ff02/T/flutter_tools.4Xdep8/generatedTargetTemplatetlN44S/conflict/conflict.file
151147
line3
152148
''', flush: true);
153149

packages/flutter_migrate/test/status_test.dart

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,11 +136,7 @@ All conflicts resolved. Review changes above and apply the migration with:
136136
conflictFile.createSync(recursive: true);
137137
conflictFile.writeAsStringSync('''
138138
line1
139-
<<<<<<< /conflcit/conflict.file
140139
line2
141-
=======
142-
linetwo
143-
>>>>>>> /var/folders/md/gm0zgfcj07vcsj6jkh_mp_wh00ff02/T/flutter_tools.4Xdep8/generatedTargetTemplatetlN44S/conflict/conflict.file
144140
line3
145141
''', flush: true);
146142
final File conflictFileOriginal =

packages/google_maps_flutter/google_maps_flutter/CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
## NEXT
1+
## 2.4.0
2+
* Adds implementation for `cloudMapId` parameter to support cloud-based maps styling.
3+
4+
## 2.3.0
25

36
* Aligns Dart and Flutter SDK constraints.
47

packages/google_maps_flutter/google_maps_flutter/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ The Android implementation supports multiple
5858
[platform view display modes](https://flutter.dev/docs/development/platform-integration/platform-views).
5959
For details, see [the Android README](https://pub.dev/packages/google_maps_flutter_android#display-mode).
6060

61+
#### Cloud-based map styling
62+
Cloud-based map styling works on Android platform only if `AndroidMapRenderer.latest` map renderer has been initialized.
63+
For details, see [the Android README](https://pub.dev/packages/google_maps_flutter_android#map-renderer).
64+
6165
### iOS
6266

6367
To set up, specify your API key in the application delegate `ios/Runner/AppDelegate.m`:

packages/google_maps_flutter/google_maps_flutter/example/integration_test/google_maps_test.dart

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const LatLng _kInitialMapCenter = LatLng(0, 0);
1717
const double _kInitialZoomLevel = 5;
1818
const CameraPosition _kInitialCameraPosition =
1919
CameraPosition(target: _kInitialMapCenter, zoom: _kInitialZoomLevel);
20+
const String _kCloudMapId = '000000000000000'; // Dummy map ID.
2021

2122
void main() {
2223
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
@@ -1165,6 +1166,32 @@ void main() {
11651166
expect(tileOverlayInfo1, isNull);
11661167
},
11671168
);
1169+
1170+
testWidgets(
1171+
'testCloudMapId',
1172+
(WidgetTester tester) async {
1173+
final Completer<int> mapIdCompleter = Completer<int>();
1174+
final Key key = GlobalKey();
1175+
1176+
await tester.pumpWidget(
1177+
Directionality(
1178+
textDirection: TextDirection.ltr,
1179+
child: GoogleMap(
1180+
key: key,
1181+
initialCameraPosition: _kInitialCameraPosition,
1182+
onMapCreated: (GoogleMapController controller) {
1183+
mapIdCompleter.complete(controller.mapId);
1184+
},
1185+
cloudMapId: _kCloudMapId,
1186+
),
1187+
),
1188+
);
1189+
1190+
// Await mapIdCompleter to finish to make sure map can be created with styledMapId
1191+
// Styled map
1192+
await mapIdCompleter.future;
1193+
},
1194+
);
11681195
}
11691196

11701197
class _DebugTileProvider implements TileProvider {

packages/google_maps_flutter/google_maps_flutter/example/lib/main.dart

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5+
import 'dart:async';
6+
57
import 'package:flutter/material.dart';
68
import 'package:google_maps_flutter_android/google_maps_flutter_android.dart';
79
import 'package:google_maps_flutter_platform_interface/google_maps_flutter_platform_interface.dart';
@@ -10,6 +12,7 @@ import 'animate_camera.dart';
1012
import 'lite_mode.dart';
1113
import 'map_click.dart';
1214
import 'map_coordinates.dart';
15+
import 'map_map_id.dart';
1316
import 'map_ui.dart';
1417
import 'marker_icons.dart';
1518
import 'move_camera.dart';
@@ -39,6 +42,7 @@ final List<GoogleMapExampleAppPage> _allPages = <GoogleMapExampleAppPage>[
3942
const SnapshotPage(),
4043
const LiteModePage(),
4144
const TileOverlayPage(),
45+
const MapIdPage(),
4246
];
4347

4448
/// MapsDemo is the Main Application.
@@ -75,6 +79,34 @@ void main() {
7579
GoogleMapsFlutterPlatform.instance;
7680
if (mapsImplementation is GoogleMapsFlutterAndroid) {
7781
mapsImplementation.useAndroidViewSurface = true;
82+
initializeMapRenderer();
7883
}
7984
runApp(const MaterialApp(home: MapsDemo()));
8085
}
86+
87+
Completer<AndroidMapRenderer?>? _initializedRendererCompleter;
88+
89+
/// Initializes map renderer to with `latest` renderer type for Android platform.
90+
/// The renderer must be requested before creating GoogleMap instances,
91+
/// as the renderer can be initialized only once per application context.
92+
Future<AndroidMapRenderer?> initializeMapRenderer() async {
93+
if (_initializedRendererCompleter != null) {
94+
return _initializedRendererCompleter!.future;
95+
}
96+
97+
_initializedRendererCompleter = Completer<AndroidMapRenderer?>();
98+
99+
WidgetsFlutterBinding.ensureInitialized();
100+
101+
final GoogleMapsFlutterPlatform mapsImplementation =
102+
GoogleMapsFlutterPlatform.instance;
103+
if (mapsImplementation is GoogleMapsFlutterAndroid) {
104+
mapsImplementation.initializeWithRenderer(AndroidMapRenderer.latest).then(
105+
(AndroidMapRenderer initializedRenderer) =>
106+
_initializedRendererCompleter!.complete(initializedRenderer));
107+
} else {
108+
_initializedRendererCompleter!.complete(null);
109+
}
110+
111+
return _initializedRendererCompleter!.future;
112+
}
Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
// ignore_for_file: public_member_api_docs
6+
7+
import 'dart:io';
8+
9+
import 'package:flutter/material.dart';
10+
import 'package:google_maps_flutter/google_maps_flutter.dart';
11+
import 'package:google_maps_flutter_android/google_maps_flutter_android.dart';
12+
import 'main.dart';
13+
import 'page.dart';
14+
15+
class MapIdPage extends GoogleMapExampleAppPage {
16+
const MapIdPage({Key? key})
17+
: super(const Icon(Icons.map), 'Cloud-based maps styling', key: key);
18+
19+
@override
20+
Widget build(BuildContext context) {
21+
return const MapIdBody();
22+
}
23+
}
24+
25+
class MapIdBody extends StatefulWidget {
26+
const MapIdBody({Key? key}) : super(key: key);
27+
28+
@override
29+
State<StatefulWidget> createState() => MapIdBodyState();
30+
}
31+
32+
const LatLng _kMapCenter = LatLng(52.4478, -3.5402);
33+
34+
class MapIdBodyState extends State<MapIdBody> {
35+
GoogleMapController? controller;
36+
37+
Key _key = const Key('mapId#');
38+
String? _mapId;
39+
final TextEditingController _mapIdController = TextEditingController();
40+
AndroidMapRenderer? _initializedRenderer;
41+
42+
@override
43+
void initState() {
44+
initializeMapRenderer()
45+
.then<void>((AndroidMapRenderer? initializedRenderer) => setState(() {
46+
_initializedRenderer = initializedRenderer;
47+
}));
48+
super.initState();
49+
}
50+
51+
String _getInitializedsRendererType() {
52+
switch (_initializedRenderer) {
53+
case AndroidMapRenderer.latest:
54+
return 'latest';
55+
case AndroidMapRenderer.legacy:
56+
return 'legacy';
57+
case AndroidMapRenderer.platformDefault:
58+
case null:
59+
break;
60+
}
61+
return 'unknown';
62+
}
63+
64+
void _setMapId() {
65+
setState(() {
66+
_mapId = _mapIdController.text;
67+
68+
// Change key to initialize new map instance for new mapId.
69+
_key = Key(_mapId ?? 'mapId#');
70+
});
71+
}
72+
73+
@override
74+
Widget build(BuildContext context) {
75+
final GoogleMap googleMap = GoogleMap(
76+
onMapCreated: _onMapCreated,
77+
initialCameraPosition: const CameraPosition(
78+
target: _kMapCenter,
79+
zoom: 7.0,
80+
),
81+
key: _key,
82+
cloudMapId: _mapId);
83+
84+
final List<Widget> columnChildren = <Widget>[
85+
Padding(
86+
padding: const EdgeInsets.all(10.0),
87+
child: Center(
88+
child: SizedBox(
89+
width: 300.0,
90+
height: 200.0,
91+
child: googleMap,
92+
),
93+
),
94+
),
95+
Padding(
96+
padding: const EdgeInsets.all(10.0),
97+
child: TextField(
98+
controller: _mapIdController,
99+
decoration: const InputDecoration(
100+
hintText: 'Map Id',
101+
),
102+
)),
103+
Padding(
104+
padding: const EdgeInsets.all(10.0),
105+
child: ElevatedButton(
106+
onPressed: () => _setMapId(),
107+
child: const Text(
108+
'Press to use specified map Id',
109+
),
110+
)),
111+
if (Platform.isAndroid)
112+
Padding(
113+
padding: const EdgeInsets.all(10.0),
114+
child: Text(
115+
'On Android, Cloud-based maps styling only works with "latest" renderer.\n\n'
116+
'Current initialized renderer is "${_getInitializedsRendererType()}".'),
117+
),
118+
if (Platform.isIOS)
119+
const Padding(
120+
padding: EdgeInsets.all(10.0),
121+
child:
122+
Text('On iOS, cloud based map styling works only if iOS platform '
123+
'version 12 or above is targeted in project Podfile. '
124+
"Run command 'pod update GoogleMaps' to update plugin"),
125+
)
126+
];
127+
128+
return Column(
129+
crossAxisAlignment: CrossAxisAlignment.stretch,
130+
children: columnChildren,
131+
);
132+
}
133+
134+
@override
135+
void dispose() {
136+
_mapIdController.dispose();
137+
super.dispose();
138+
}
139+
140+
void _onMapCreated(GoogleMapController controllerParam) {
141+
setState(() {
142+
controller = controllerParam;
143+
});
144+
}
145+
}

packages/google_maps_flutter/google_maps_flutter/example/pubspec.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,15 @@ flutter:
3535
uses-material-design: true
3636
assets:
3737
- assets/
38+
39+
40+
# FOR TESTING ONLY. DO NOT MERGE.
41+
dependency_overrides:
42+
google_maps_flutter:
43+
path: ../../../google_maps_flutter/google_maps_flutter
44+
google_maps_flutter_android:
45+
path: ../../../google_maps_flutter/google_maps_flutter_android
46+
google_maps_flutter_ios:
47+
path: ../../../google_maps_flutter/google_maps_flutter_ios
48+
google_maps_flutter_platform_interface:
49+
path: ../../../google_maps_flutter/google_maps_flutter_platform_interface

packages/google_maps_flutter/google_maps_flutter/lib/src/google_map.dart

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,9 @@ class GoogleMap extends StatefulWidget {
123123
this.onCameraIdle,
124124
this.onTap,
125125
this.onLongPress,
126-
}) : assert(initialCameraPosition != null);
126+
this.cloudMapId,
127+
}) : assert(initialCameraPosition != null),
128+
super(key: key);
127129

128130
/// Callback method for when the map is ready to be used.
129131
///
@@ -282,6 +284,12 @@ class GoogleMap extends StatefulWidget {
282284
/// were not claimed by any other gesture recognizer.
283285
final Set<Factory<OneSequenceGestureRecognizer>> gestureRecognizers;
284286

287+
/// Identifier that's associated with a specific cloud-based map style.
288+
///
289+
/// See https://developers.google.com/maps/documentation/get-map-id
290+
/// for more details.
291+
final String? cloudMapId;
292+
285293
/// Creates a [State] for this [GoogleMap].
286294
@override
287295
State createState() => _GoogleMapState();
@@ -552,5 +560,6 @@ MapConfiguration _configurationFromMapWidget(GoogleMap map) {
552560
indoorViewEnabled: map.indoorViewEnabled,
553561
trafficEnabled: map.trafficEnabled,
554562
buildingsEnabled: map.buildingsEnabled,
563+
cloudMapId: map.cloudMapId,
555564
);
556565
}

packages/google_maps_flutter/google_maps_flutter/pubspec.yaml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: google_maps_flutter
22
description: A Flutter plugin for integrating Google Maps in iOS and Android applications.
33
repository: https://github.com/flutter/packages/tree/main/packages/google_maps_flutter/google_maps_flutter
44
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+maps%22
5-
version: 2.2.5
5+
version: 2.4.0
66

77
environment:
88
sdk: ">=2.17.0 <4.0.0"
@@ -20,11 +20,20 @@ dependencies:
2020
flutter:
2121
sdk: flutter
2222
google_maps_flutter_android: ^2.1.10
23-
google_maps_flutter_ios: ^2.1.10
2423
google_maps_flutter_platform_interface: ^2.2.1
2524

2625
dev_dependencies:
2726
flutter_test:
2827
sdk: flutter
2928
plugin_platform_interface: ^2.0.0
3029
stream_transform: ^2.0.0
30+
31+
32+
# FOR TESTING ONLY. DO NOT MERGE.
33+
dependency_overrides:
34+
google_maps_flutter_android:
35+
path: ../../google_maps_flutter/google_maps_flutter_android
36+
google_maps_flutter_ios:
37+
path: ../../google_maps_flutter/google_maps_flutter_ios
38+
google_maps_flutter_platform_interface:
39+
path: ../../google_maps_flutter/google_maps_flutter_platform_interface

packages/google_maps_flutter/google_maps_flutter_android/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 2.5.0
2+
3+
* Adds implementation for `cloudMapId` parameter to support cloud-based map styling.
4+
15
## 2.4.10
26

37
* Bump RoboElectric dependency to 4.4.1 to support AndroidX.

packages/google_maps_flutter/google_maps_flutter_android/android/src/main/java/io/flutter/plugins/googlemaps/Convert.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,10 @@ static void interpretGoogleMapOptions(Object o, GoogleMapOptionsSink sink) {
377377
if (buildingsEnabled != null) {
378378
sink.setBuildingsEnabled(toBoolean(buildingsEnabled));
379379
}
380+
final Object cloudMapId = data.get("cloudMapId");
381+
if (buildingsEnabled != null) {
382+
sink.setMapId(toString(cloudMapId));
383+
}
380384
}
381385

382386
/** Returns the dartMarkerId of the interpreted marker. */

packages/google_maps_flutter/google_maps_flutter_android/android/src/main/java/io/flutter/plugins/googlemaps/GoogleMapBuilder.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,4 +174,9 @@ public void setInitialCircles(Object initialCircles) {
174174
public void setInitialTileOverlays(List<Map<String, ?>> initialTileOverlays) {
175175
this.initialTileOverlays = initialTileOverlays;
176176
}
177+
178+
@Override
179+
public void setMapId(String mapId) {
180+
options.mapId(mapId);
181+
}
177182
}

0 commit comments

Comments
 (0)