This repository was archived by the owner on Feb 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9.8k
[google_maps_flutter] Cloud-based map styling support #6553
Closed
jokerttu
wants to merge
6
commits into
flutter:main
from
CodemateLtd:google_maps_flutter_map_id_support
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
42cbd75
[google_maps_flutter] cloud-based map id support
jokerttu 7e09827
[google_maps_flutter] examples - move renderer initialization
jokerttu 728053b
[google_maps_flutter] Fix versioning
jokerttu 685b8f1
[google_maps_flutter] updated tests and documentation
jokerttu e8efba6
[google_maps_flutter] Fix readme
jokerttu 2673fb3
Fix violations
jokerttu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
145 changes: 145 additions & 0 deletions
145
packages/google_maps_flutter/google_maps_flutter/example/lib/map_map_id.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
// Copyright 2013 The Flutter Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
// ignore_for_file: public_member_api_docs | ||
|
||
import 'dart:io'; | ||
|
||
import 'package:flutter/material.dart'; | ||
import 'package:google_maps_flutter/google_maps_flutter.dart'; | ||
import 'package:google_maps_flutter_android/google_maps_flutter_android.dart'; | ||
import 'main.dart'; | ||
import 'page.dart'; | ||
|
||
class MapIdPage extends GoogleMapExampleAppPage { | ||
const MapIdPage({Key? key}) | ||
: super(const Icon(Icons.map), 'Cloud-based maps styling', key: key); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return const MapIdBody(); | ||
} | ||
} | ||
|
||
class MapIdBody extends StatefulWidget { | ||
const MapIdBody({Key? key}) : super(key: key); | ||
|
||
@override | ||
State<StatefulWidget> createState() => MapIdBodyState(); | ||
} | ||
|
||
const LatLng _kMapCenter = LatLng(52.4478, -3.5402); | ||
|
||
class MapIdBodyState extends State<MapIdBody> { | ||
GoogleMapController? controller; | ||
|
||
Key _key = const Key('mapId#'); | ||
String? _mapId; | ||
final TextEditingController _mapIdController = TextEditingController(); | ||
AndroidMapRenderer? _initializedRenderer; | ||
|
||
@override | ||
void initState() { | ||
initializeMapRenderer() | ||
.then<void>((AndroidMapRenderer? initializedRenderer) => setState(() { | ||
_initializedRenderer = initializedRenderer; | ||
})); | ||
super.initState(); | ||
} | ||
|
||
String _getInitializedsRendererType() { | ||
switch (_initializedRenderer) { | ||
case AndroidMapRenderer.latest: | ||
return 'latest'; | ||
case AndroidMapRenderer.legacy: | ||
return 'legacy'; | ||
case AndroidMapRenderer.platformDefault: | ||
case null: | ||
break; | ||
} | ||
return 'unknown'; | ||
} | ||
|
||
void _setMapId() { | ||
setState(() { | ||
_mapId = _mapIdController.text; | ||
|
||
// Change key to initialize new map instance for new mapId. | ||
_key = Key(_mapId ?? 'mapId#'); | ||
}); | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
final GoogleMap googleMap = GoogleMap( | ||
onMapCreated: _onMapCreated, | ||
initialCameraPosition: const CameraPosition( | ||
target: _kMapCenter, | ||
zoom: 7.0, | ||
), | ||
key: _key, | ||
cloudMapId: _mapId); | ||
|
||
final List<Widget> columnChildren = <Widget>[ | ||
Padding( | ||
padding: const EdgeInsets.all(10.0), | ||
child: Center( | ||
child: SizedBox( | ||
width: 300.0, | ||
height: 200.0, | ||
child: googleMap, | ||
), | ||
), | ||
), | ||
Padding( | ||
padding: const EdgeInsets.all(10.0), | ||
child: TextField( | ||
controller: _mapIdController, | ||
decoration: const InputDecoration( | ||
hintText: 'Map Id', | ||
), | ||
)), | ||
Padding( | ||
padding: const EdgeInsets.all(10.0), | ||
child: ElevatedButton( | ||
onPressed: () => _setMapId(), | ||
child: const Text( | ||
'Press to use specified map Id', | ||
), | ||
)), | ||
if (Platform.isAndroid) | ||
Padding( | ||
padding: const EdgeInsets.all(10.0), | ||
child: Text( | ||
'On Android, Cloud-based maps styling only works with "latest" renderer.\n\n' | ||
'Current initialized renderer is "${_getInitializedsRendererType()}".'), | ||
), | ||
if (Platform.isIOS) | ||
const Padding( | ||
padding: EdgeInsets.all(10.0), | ||
child: | ||
Text('On iOS, cloud based map styling works only if iOS platform ' | ||
'version 12 or above is targeted in project Podfile. ' | ||
"Run command 'pod update GoogleMaps' to update plugin"), | ||
) | ||
]; | ||
|
||
return Column( | ||
crossAxisAlignment: CrossAxisAlignment.stretch, | ||
children: columnChildren, | ||
); | ||
} | ||
|
||
@override | ||
void dispose() { | ||
_mapIdController.dispose(); | ||
super.dispose(); | ||
} | ||
|
||
void _onMapCreated(GoogleMapController controllerParam) { | ||
setState(() { | ||
controller = controllerParam; | ||
}); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
packages/google_maps_flutter/google_maps_flutter_android/CHANGELOG.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
The README should be updated to explain the requirement here, and this should have a comment referring to that to explain why it's here.
Uh oh!
There was an error while loading. Please reload this page.
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.
Map renderers are already explained under google_maps_flutter_android package README.
I can update the app-facing plugin README and add information that cloud-based mapid works only on Android if latest renderer is used.
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.
README updated