Skip to content

Instantly share code, notes, and snippets.

@eric-taix
Last active January 26, 2021 00:28
Show Gist options
  • Save eric-taix/9fb19ae95aed8259d7ef99741d1cfa88 to your computer and use it in GitHub Desktop.
Save eric-taix/9fb19ae95aed8259d7ef99741d1cfa88 to your computer and use it in GitHub Desktop.
Google map with styles
import 'package:flutter/services.dart' show rootBundle;
class _MapOnSteroids extends State<MapOnSteroids> {
Completer<GoogleMapController> _controllerCompleter = Completer();
String _mapStyle;
bool _mapStyleLoaded = false;
@override
void initState() {
super.initState();
rootBundle.loadString('assets/map/style.json').then((jsonStyle) {
setState(() {
_mapStyle = jsonStyle;
_mapStyleLoaded = true;
});
});
}
@override
Widget build(BuildContext context) {
return _mapStyleLoaded ?
GoogleMap(
mapType: MapType.normal,
onMapCreated: (GoogleMapController controller) {
controller.setMapStyle(_mapStyle);
_controllerCompleter.complete(controller);
},
) :
SizedBox();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment