Display a map

Learn how to create and display a with a .

display a map

A map contains of geographic data. A map contains a and, optionally, one or more . You can display a specific area of a map by using a and setting the and .

In this tutorial, you create and display a of the Santa Monica Mountains in California using the topographic .

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 and you have set up your environment for Flutter development.

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

Steps

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.
    1
    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:

    1
      cd display_a_map
  2. Run:

    1
    dart pub add arcgis_maps
  3. Run:

    1
    flutter pub upgrade
  4. Lastly, run:

    1
    dart run arcgis_maps install

Platform specific configuration

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

    build.gradle
    8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    android {
        namespace = "com.example.app.display_a_map"
        compileSdk = flutter.compileSdkVersion
        ndkVersion = "25.2.9519653"
    
        compileOptions {
            sourceCompatibility = JavaVersion.VERSION_1_8
            targetCompatibility = JavaVersion.VERSION_1_8
        }
    
        kotlinOptions {
            jvmTarget = JavaVersion.VERSION_1_8
        }
    
        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 = 26
            targetSdk = flutter.targetSdkVersion
            versionCode = flutter.versionCode
            versionName = flutter.versionName
        }
    
  2. Update the Kotlin version by editing android/settings.gradle file in your project:

    settings.gradle
    19 20 21 22 23
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    plugins {
        id "dev.flutter.flutter-plugin-loader" version "1.0.0"
        id "com.android.application" version "8.1.0" apply false
        id "org.jetbrains.kotlin.android" version "1.9.0" apply false
    }
    
  3. Add a permission to android/app/src/main/AndroidManifest.xml to access online resources:

    AndroidManifest.xml
    2 3 4 5 6 7 8
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    
    <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">
    

Get an access token

You need an to use the used in this tutorial.

  1. Go to the Create an API key tutorial to obtain an using your or account.

  2. Ensure that the following is enabled: Location services > Basemaps > Basemap styles service.

  3. Copy the access token as it will be used in the next step.

To learn more about other ways to get an access token, go to Types of authentication.

Set your API key

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

  2. Import the arcgis_maps package.

    main.dart
    2 3 4 5
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    
    import 'package:flutter/material.dart';
    
    import 'package:arcgis_maps/arcgis_maps.dart';
    
  3. In the main() function, define a const apiKey and set its value with your .

    main.dart
    6 7 8 9 10 11
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    void main() {
    
      const apiKey = ''; // Your access token here.
    
      runApp(const MainApp());
    }
    
  4. Set the ArcGISEnvironment.apiKey to the apiKey constant.

    main.dart
    6 7 8 9 10 11 12 13
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    void main() {
    
      const apiKey = ''; // Your access token here.
    
      ArcGISEnvironment.apiKey = apiKey;
    
      runApp(const MainApp());
    }
    
  5. Instantiate MaterialApp inside runApp() and set the named argument, home, to an instance of MainApp.

    main.dart
    17 18 19 20 21 22 23 24 25 26 27 28 29 30
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    void main() {
    
      const apiKey = ''; // Your access token here.
    
      ArcGISEnvironment.apiKey = apiKey;
    
      runApp(
    
        const MaterialApp(
          home: MainApp(),
        ),
    
      );
    }
    

Add a map

Create a that contains a topographic . 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
    25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    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!'),
            ),
          ),
        );
    
      }
    }
  2. Remove the MaterialApp widget that is returned within the build method. 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
    25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    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!'),
            ),
          ),
        );
    
      }
    }
  3. 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
    49 50 51 52 53 54 55 56 57 58
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    class _MainAppState extends State<MainApp> {
    
      final _mapViewController = ArcGISMapView.createController();
    
      @override
      Widget build(BuildContext context) {
    
      }
    
    }
  4. Within the build method, add an ArcGISMapView 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
    49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    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,
                ),
              ),
            ],
          ),
        );
    
      }
    
    }
  5. Within _MainAppState, define a new method: onMapViewReady() that does not return anything.

    main.dart
    49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    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() {
    
      }
    
    }
  6. Within the new method define a final variable, map, and initialize it to an ArcGISMap with the ArcGIS Topographic basemap style.

    main.dart
    49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    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);
    
      }
    
    }
  7. 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
    49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    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.

Run download solution

If you have downloaded the project solution, follow these steps to run the application.

  1. Open the extracted project in VS code.

  2. In VS Code's terminal, run:

    1
      flutter pub upgrade
  3. Run:

    1
      dart run arcgis_maps install
  4. Make sure to get an access token and set your API key in the lib/main.dart source code file.

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

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

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.

You can no longer sign into this site. Go to your ArcGIS portal or the ArcGIS Location Platform dashboard to perform management tasks.

Your ArcGIS portal

Create, manage, and access API keys and OAuth 2.0 developer credentials, hosted layers, and data services.

Your ArcGIS Location Platform dashboard

Manage billing, monitor service usage, and access additional resources.

Learn more about these changes in the What's new in Esri Developers June 2024 blog post.

Close