Learn how to create and display a mapA map is a collection of layers that are displayed in 2D. It is typically composed of a basemap layer and data layers. Learn more with a basemap layerA basemap layer is the layer in a map or scene that displays basemap data. The data source for a basemap layer is typically a basemap service. Learn more .

Map centered on Point Dume State Beach in California shown in a Flutter app on tablet and phone layouts.

A map contains layersA layer is a reference to a collection of geographic data that is used to access and display data. The data for layers are typically provided by the basemap layer service and data services. Learn more of geographic data. A map contains a basemap layerA basemap layer is the layer in a map or scene that displays basemap data. The data source for a basemap layer is typically a basemap service. Learn more and, optionally, one or more data layersA data layer is a layer that references geographic data from a file or a service and is used to visualize the data in a map or scene. Learn more . You can display a specific area of a map by using a map viewA map view is a user interface that displays map layers and graphics in 2D. It controls the area (extent) of the map that is visible and supports user interactions such as pan and zoom. Learn more and setting the locationA location is a position or region (point, line, or polygon) on the earth's surface. Learn more and zoom levelZoom level is a value that sets the scale for a map view or a scene view. Learn more .

In this tutorial, you create and display a mapA map is a collection of layers that are displayed in 2D. It is typically composed of a basemap layer and data layers. Learn more of the Santa Monica Mountains in California using the topographic basemap layerA basemap layer is the layer in a map or scene that displays basemap data. The data source for a basemap layer is typically a basemap service. Learn more .

The map and code will be used as the starting point for other 2D tutorials.

Prerequisites

Before starting this tutorial:

  1. You need an ArcGIS Location Platform or ArcGIS Online account.

  2. Your system meets the system requirements.

  3. You need an IDE for Flutter - we recommend VS Code.

Set up authentication

To access the secure ArcGIS location servicesArcGIS Location Services, also referred to as Location Services, are services hosted by Esri that provide geospatial functionality for developing mapping applications. They include the ArcGIS Basemap Styles service, ArcGIS Static Basemap Tiles service, ArcGIS Static Maps service, ArcGIS Places service, ArcGIS Geocoding service, ArcGIS Routing service, ArcGIS GeoEnrichment service, and ArcGIS Elevation service. An ArcGIS Location Platform or ArcGIS Online account is required to use the services. Learn more used in this tutorial, you must implement API key authenticationAPI key authentication is a type of authentication that uses an API key to authenticate requests to ArcGIS services and secure portal items. Learn more using an ArcGIS Location PlatformAn ArcGIS Location Platform account, formerly known as an ArcGIS Developer account, is an identity associated with an ArcGIS Location Platform subscription. Learn more or an ArcGIS OnlineAn ArcGIS Online account, also known as an ArcGIS Organization account, is an identity associated with an ArcGIS Online subscription. It can be used to access ArcGIS tools and develop applications with ArcGIS location services for an organization. Learn more account.

Create a new API key access tokenAn access token is an authorization string that provides access to secure ArcGIS content, data, and services. Its capabilities are determined by the privileges it supports. It is obtained by implementing API key authentication, User authentication, or App authentication. Learn more with privilegesPrivileges are a set of permissions assigned to ArcGIS accounts, developer credentials, and applications that grant access to secure resources and functionality in ArcGIS. Learn more to access the secure resources used in this tutorial.

  1. Complete the Create an API key tutorial and create an API key with the following privilege(s)Privileges are a set of permissions assigned to ArcGIS accounts, developer credentials, and applications that grant access to secure resources and functionality in ArcGIS. Learn more :

    • Privileges
      • Location services > Basemaps
  2. Copy and paste the API key access token into a safe location. It will be used in a later step.

Develop or download

You have two options for completing this tutorial:

  1. Option 1: Develop the code or
  2. Option 2: Download the completed solution

Option 1: Develop the code

Create a new Flutter app

  1. Open VS Code, then select Open Folder… in the welcome tab. Choose your preferred project location.

  2. Go to View > Terminal.

  3. In the terminal window, use the following command to create a new Flutter app called display_a_map. Set your required target platform(s) and an org name, com.example.app.

    flutter create -e display_a_map --platforms ios,android --org com.example.app

    Add ArcGIS Maps SDK for Flutter

    Add a dependency to the arcgis_maps package.

    1. In VS Code’s terminal, change the directory to your new project:

      cd display_a_map
      • Run:

        dart pub add arcgis_maps
        • Run:

          flutter pub upgrade
          • Lastly, run:

            dart run arcgis_maps install

            Platform specific configuration

            1. Update the minimum requirements by editing android/app/build.gradle.kts file in your project:

              build.gradle.kts
              android {
              namespace = "com.example.app.display_a_map"
              compileSdk = 36
              ndkVersion = "27.0.12077973"
              // ...
              defaultConfig {
              // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
              applicationId = "com.example.app.display_a_map"
              // You can update the following values to match your application needs.
              // For more information, see: https://flutter.dev/to/review-gradle-config.
              minSdk = 28
              targetSdk = flutter.targetSdkVersion
              versionCode = flutter.versionCode
              versionName = flutter.versionName
              }
              // ...
              • Add a permission to android/app/src/main/AndroidManifest.xml to access online resources:

                AndroidManifest.xml
                <manifest xmlns:android="http://schemas.android.com/apk/res/android">
                <uses-permission android:name="android.permission.INTERNET" />
                <application
                android:label="display_a_map"
                android:name="${applicationName}"
                android:icon="@mipmap/ic_launcher">
                <!-- ... -->

                Set developer credentials

                To allow your app users to access ArcGIS location servicesArcGIS Location Services, also referred to as Location Services, are services hosted by Esri that provide geospatial functionality for developing mapping applications. They include the ArcGIS Basemap Styles service, ArcGIS Static Basemap Tiles service, ArcGIS Static Maps service, ArcGIS Places service, ArcGIS Geocoding service, ArcGIS Routing service, ArcGIS GeoEnrichment service, and ArcGIS Elevation service. An ArcGIS Location Platform or ArcGIS Online account is required to use the services. Learn more , use the developer credentials that you created in the Set up authentication step to authenticate requests for resources.

                1. In VS Code, open lib/main.dart.

                2. Import the arcgis_maps package.

                  main.dart
                  import 'package:flutter/material.dart';
                  import 'package:arcgis_maps/arcgis_maps.dart';
                  • In the main() function, set the ArcGISEnvironment.apiKey value to your access tokenAn access token is an authorization string that provides access to secure ArcGIS content, data, and services. Its capabilities are determined by the privileges it supports. It is obtained by implementing API key authentication, User authentication, or App authentication. Learn more .

                    main.dart
                    void main() {
                    ArcGISEnvironment.apiKey = 'YOUR_ACCESS_TOKEN';
                    runApp(const MainApp());
                    }

                      Best Practice: The access token is stored directly in the code as a convenience for this tutorial. Do not store credentials directly in source code in a production environment.

                    • Instantiate MaterialApp inside runApp() and set the named argument, home, to an instance of MainApp.

                      main.dart
                      void main() {
                      ArcGISEnvironment.apiKey = 'YOUR_ACCESS_TOKEN';
                      runApp(
                      const MaterialApp(home: MainApp())
                      );
                      }

                      Add a map

                      Create a mapA map is a collection of layers that are displayed in 2D. It is typically composed of a basemap layer and data layers. Learn more that contains a topographic basemap layerA basemap layer is the layer in a map or scene that displays basemap data. The data source for a basemap layer is typically a basemap service. Learn more . The map will be centered on the Santa Monica Mountains in California.

                      1. Refactor the template MainApp class definition to extend StatefulWidget. Hover your mouse over the StatelessWidget keyword, right-click, select Refactor…, and chose Convert to StatefulWidget to refactor your code.

                        main.dart
                        class MainApp extends StatefulWidget {
                        const MainApp({super.key});
                        @override
                        State<MainApp> createState() => _MainAppState();
                        }
                        class _MainAppState extends State<MainApp> {
                        @override
                        Widget build(BuildContext context) {
                        return const MaterialApp(
                        home: Scaffold(body: Center(child: Text('Hello World!'))),
                        );
                        }
                        }
                        • Remove the MaterialApp widget that is returned within the build method of class _MainAppState. This code was generated by the Flutter create template and will be replaced with code to return a widget that contains a map next.

                          main.dart
                          class _MainAppState extends State<MainApp> {
                          @override
                          Widget build(BuildContext context) {
                          return const MaterialApp(
                          home: Scaffold(body: Center(child: Text('Hello World!'))),
                          );
                          }
                          }
                          • Inside _MainAppState class define a final class member variable, _mapViewController, and initialize it with ArcGISMapViewController by calling the createController() on the ArcGISMapView class.

                            main.dart
                            class _MainAppState extends State<MainApp> {
                            final _mapViewController = ArcGISMapView.createController();
                            @override
                            Widget build(BuildContext context) {
                            }
                            }
                            • Within the build method, add an widget to the widget tree consisting of Scaffold, Column, and Expanded. Set the named argument, controllerProvider, to the class member variable _mapViewController and the onMapViewReady argument to a new method with the same name as the argument that you will define next.

                              main.dart
                              class _MainAppState extends State<MainApp> {
                              final _mapViewController = ArcGISMapView.createController();
                              @override
                              Widget build(BuildContext context) {
                              return Scaffold(
                              body: Column(
                              children: [
                              Expanded(
                              child: ArcGISMapView(
                              controllerProvider: () => _mapViewController,
                              onMapViewReady: onMapViewReady,
                              ),
                              ),
                              ],
                              ),
                              );
                              }
                              }
                              • Within _MainAppState, define a new method: onMapViewReady() that does not return anything.

                                main.dart
                                class _MainAppState extends State<MainApp> {
                                final _mapViewController = ArcGISMapView.createController();
                                @override
                                Widget build(BuildContext context) {
                                return Scaffold(
                                body: Column(
                                children: [
                                Expanded(
                                child: ArcGISMapView(
                                controllerProvider: () => _mapViewController,
                                onMapViewReady: onMapViewReady,
                                ),
                                ),
                                ],
                                ),
                                );
                                }
                                void onMapViewReady() {
                                }
                                }
                                • Within the new method define a final variable, map, and initialize it to an ArcGISMap with the ArcGIS Topographic basemap style.

                                  main.dart
                                  class _MainAppState extends State<MainApp> {
                                  final _mapViewController = ArcGISMapView.createController();
                                  @override
                                  Widget build(BuildContext context) {
                                  return Scaffold(
                                  body: Column(
                                  children: [
                                  Expanded(
                                  child: ArcGISMapView(
                                  controllerProvider: () => _mapViewController,
                                  onMapViewReady: onMapViewReady,
                                  ),
                                  ),
                                  ],
                                  ),
                                  );
                                  }
                                  void onMapViewReady() {
                                  final map = ArcGISMap.withBasemapStyle(BasemapStyle.arcGISTopographic);
                                  }
                                  }
                                  • Set the ArcGIS map view controller’s arcGISMap property to the map. In addition, call setViewpoint() to zoom to the Santa Monica Mountains in California.

                                    main.dart
                                    class _MainAppState extends State<MainApp> {
                                    final _mapViewController = ArcGISMapView.createController();
                                    @override
                                    Widget build(BuildContext context) {
                                    return Scaffold(
                                    body: Column(
                                    children: [
                                    Expanded(
                                    child: ArcGISMapView(
                                    controllerProvider: () => _mapViewController,
                                    onMapViewReady: onMapViewReady,
                                    ),
                                    ),
                                    ],
                                    ),
                                    );
                                    }
                                    void onMapViewReady() {
                                    final map = ArcGISMap.withBasemapStyle(BasemapStyle.arcGISTopographic);
                                    _mapViewController.arcGISMap = map;
                                    _mapViewController.setViewpoint(
                                    Viewpoint.withLatLongScale(
                                    latitude: 34.02700,
                                    longitude: -118.80500,
                                    scale: 72000,
                                    ),
                                    );
                                    }
                                    }

                                    Run the app

                                    1. Make sure you have an Android emulator, iOS simulator or physical device configured and running.

                                    2. In VS Code, select Run > Run Without Debugging.

                                    You will see a mapA map is a collection of layers that are displayed in 2D. It is typically composed of a basemap layer and data layers. Learn more with the topographic basemap layerA basemap layer is the layer in a map or scene that displays basemap data. The data source for a basemap layer is typically a basemap service. Learn more centered on the Santa Monica Mountains in California. Pinch, drag, and double-tap the map view to explore the map.

                                    Alternatively, you can download the tutorial solution, as follows.

                                    Option 2: Download the solution

                                    1. Click the Download solution link under Solution and unzip the file to a location on your machine.

                                    2. Open the project in VS code.

                                    Since the downloaded solution does not contain authentication credentials, you must add the developer credentials that you created in the Set up authentication section.

                                    Set developer credentials in the solution

                                    To allow your app users to access ArcGIS location servicesArcGIS Location Services, also referred to as Location Services, are services hosted by Esri that provide geospatial functionality for developing mapping applications. They include the ArcGIS Basemap Styles service, ArcGIS Static Basemap Tiles service, ArcGIS Static Maps service, ArcGIS Places service, ArcGIS Geocoding service, ArcGIS Routing service, ArcGIS GeoEnrichment service, and ArcGIS Elevation service. An ArcGIS Location Platform or ArcGIS Online account is required to use the services. Learn more , use the developer credentials that you created in the Set up authentication step to authenticate requests for resources.

                                    1. In VS Code, open lib/main.dart.

                                    2. In the main() function, set the ArcGISEnvironment.apiKey value to your access tokenAn access token is an authorization string that provides access to secure ArcGIS content, data, and services. Its capabilities are determined by the privileges it supports. It is obtained by implementing API key authentication, User authentication, or App authentication. Learn more .

                                      main.dart
                                      void main() {
                                      ArcGISEnvironment.apiKey = 'YOUR_ACCESS_TOKEN';
                                      runApp(const MainApp());
                                      }

                                        Best Practice: The access token is stored directly in the code as a convenience for this tutorial. Do not store credentials directly in source code in a production environment.

                                      Run the application

                                      Follow these steps to run the application.

                                      1. In VS Code’s terminal, run:

                                        flutter pub upgrade
                                        • Run:

                                          dart run arcgis_maps install
                                          • Make sure you have an Android emulator, iOS simulator or physical device configured and running.

                                          • In VS Code, select Run > Run Without Debugging.

                                          You will see a mapA map is a collection of layers that are displayed in 2D. It is typically composed of a basemap layer and data layers. Learn more with the topographic basemap layerA basemap layer is the layer in a map or scene that displays basemap data. The data source for a basemap layer is typically a basemap service. Learn more centered on the Santa Monica Mountains in California. Pinch, drag, and double-tap the map view to explore the map.