-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[google_maps_flutter] cloud-based map styling implementation (#4638)
This PR is sub-PR splitted out from the #3682 containing only following packages: - google_maps_flutter_web - google_maps_flutter_android - google_maps_flutter_ios Related to issue flutter/flutter#67631
- Loading branch information
Showing
32 changed files
with
499 additions
and
19 deletions.
There are no files selected for viewing
This file contains 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
4 changes: 3 additions & 1 deletion
4
packages/google_maps_flutter/google_maps_flutter_android/CHANGELOG.md
This file contains 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 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 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 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 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 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
138 changes: 138 additions & 0 deletions
138
packages/google_maps_flutter/google_maps_flutter_android/example/lib/map_map_id.dart
This file contains 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,138 @@ | ||
// 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 'package:flutter/material.dart'; | ||
import 'package:google_maps_flutter_android/google_maps_flutter_android.dart'; | ||
import 'package:google_maps_flutter_platform_interface/google_maps_flutter_platform_interface.dart'; | ||
|
||
import 'example_google_map.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({super.key}); | ||
|
||
@override | ||
State<StatefulWidget> createState() => MapIdBodyState(); | ||
} | ||
|
||
const LatLng _kMapCenter = LatLng(52.4478, -3.5402); | ||
|
||
class MapIdBodyState extends State<MapIdBody> { | ||
ExampleGoogleMapController? 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 ExampleGoogleMap googleMap = ExampleGoogleMap( | ||
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 (_initializedRenderer != AndroidMapRenderer.latest) | ||
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()}".'), | ||
), | ||
]; | ||
|
||
return Column( | ||
crossAxisAlignment: CrossAxisAlignment.stretch, | ||
children: columnChildren, | ||
); | ||
} | ||
|
||
@override | ||
void dispose() { | ||
_mapIdController.dispose(); | ||
super.dispose(); | ||
} | ||
|
||
void _onMapCreated(ExampleGoogleMapController controllerParam) { | ||
setState(() { | ||
controller = controllerParam; | ||
}); | ||
} | ||
} |
This file contains 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 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 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.