Show a Map
Your environment is now fully configured, and you have the necessary map platform and MapsIndoors API keys. Next you will learn how to load a map with MapsIndoors.
Lets start by setting up a simple app with a stateful map widget to contain the app.
First add the app to your main and import mapsindoors
import 'package:mapsindoors_mapbox/mapsindoors.dart';
import 'package:flutter/material.dart';
void main() {
runApp(const MapsIndoorsDemoApp());
}
class MapsIndoorsDemoApp extends StatelessWidget {
const MapsIndoorsDemoApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter MapsIndoors Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
);
}
}Now we can create the stateful widget, we require a mapsindoors API key when constructing the map, to ensure the map is only linked to a single mapsindoors instance.
Now we can add the Map to our App
Initialize MapsIndoors
We start by loading MapsIndoors. MapsIndoors is used to get and store all references to MapsIndoors-specific data. This includes access to all MapsIndoors-specific geodata.
Place the following initialization code in the initState method of your apps State that displays the Google map, Ensure that the loadMapsIndoors callback returns before accessing other MapsIndoors methods.
If you are not a customer you can use this demo MapsIndoors API key mapspeople3d.
Initialize MapsIndoorsWidget
We now want to add all the data we get by initializing MapsIndoors to our map. This is done by initializing MapsIndoorsWidget onto the map. MapsIndoorsWidget is used as a layer between the map and MapsIndoors.
First add the MapsIndoorsWidget to the build hierarchy, in this example it is placed in the body of a Scaffold, but it can be placed anywhere, just ensure there is enough space to use the map comfortably.
Then create a OnMapReadyListener method to handle the callback from initializing MapsIndoorsWidget:
Expected result:

See the full example of the app here: main.dart
Last updated
Was this helpful?