Last active
January 26, 2021 00:28
-
-
Save eric-taix/9fb19ae95aed8259d7ef99741d1cfa88 to your computer and use it in GitHub Desktop.
Google map with styles
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
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