In the state of a StatefulWidget, add this:
static const String apiKey = "API-KEY"; //Put apiKey provided by Lazarillo
final _lazarilloMapsPlugin = LazarilloMaps(apiKey);
Widget? _lzMapWidget;Then, add the initial configuration required by the map:
static const initialCenter = LatLng(-33.4190, -70.6419);
MapConfiguration mapConfiguration = MapConfiguration(
parentPlaceId: "ID de Place",
latitude: initialCenter.latitude,
longitude: initialCenter.longitude);After that, init the state of the widget with the calls necessary
@override
void initState() {
super.initState();
initMapState();
}
Future<void> initMapState() async {
await _lazarilloMapsPlugin.initialize();
Widget? lzMap = _lazarilloMapsPlugin.getLazarilloMapWidget(
mapConfiguration, (mapId) => debugPrint('Map ready: $mapId'));
setState(() {
_lzMapWidget = lzMap;
});
}Finally, add the lzMap widget to your build() method where your need the map to be, in this case we use a SizezBox to resize the size of the map in the widget to whatever size we like:
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Plugin example app'),
),
body: Center(
child: Column(
children: [
Text('Map example'),
if (_lzMapWidget != null)
SizedBox(
height: 300,
child: _lzMapWidget!,
)
],
),
),
),
);
}Last updated on