Skip to content

Display an offline map (on-demand)

Learn how to download and display an offline map for a user-defined geographical area of a web map.

display an offline map on demand

Offline maps allow users to continue working when network connectivity is poor or lost. If a web map is enabled for offline use, a user can request that ArcGIS generates an offline map for a specified geographic area of interest.

In this tutorial, you will download an offline map for an area of interest from the web map of the stormwater network within Naperville, IL, USA . You can then use this offline map without a network connection.

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.

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

To start the tutorial, complete the Display a map tutorial. This creates a map to display the Santa Monica Mountains in California using the topographic basemap from the ArcGIS Basemap Styles service.

Open Flutter project

  1. Open the project you created by completing the Display a map tutorial.

  2. Continue with the following instructions to download and display an offline map for a user-defined geographical area of a web map.

Import additional library and package

As part of the offline workflow, you will need to store a downloaded map to your device. You will add the dart:io library to gain access to an API to deal with files and directories and the path_provider package to access local files on a device.

  1. In VS Code, double-click lib\main.dart to open the file.

  2. From the menu bar, select View > Terminal to open a new terminal.

  3. Add the path_provider package to the project as a dependency running the following command:

    Use dark colors for code blocksCopy
    1
    flutter pub add path_provider
  4. Import path_provider and dart.io into main.dart.

    main.dart
    Use dark colors for code blocks
    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
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    import 'dart:io';
    import 'package:path_provider/path_provider.dart';
    
    import 'package:flutter/material.dart';
    import 'package:arcgis_maps/arcgis_maps.dart';
    
    void main() {
    

Get the web map item ID

You can use ArcGIS tools to create and view web maps. Use the Map Viewer to identify the web map item ID. This item ID will be used later in the tutorial.

  1. Go to the Naperville water network in the Map Viewer in ArcGIS Online. This web map displays stormwater network within Naperville, IL, USA .
  2. Make a note of the item ID at the end of the browser's URL. The item ID should be:

    acc027394bc84c2fb04d1ed317aac674

Display the web map

You can display a web map using the web map's item ID. Create a map from the web map portal item, and display it in your app.

  1. Replace all the code contained in onMapViewReady() to instead create a portal item using the item ID from the ArcGIS Online web map.

    main.dart
    Use dark colors for code blocks
    1
    2
    3
    4
    5
    6
    7
    8
    9
    void onMapViewReady() {
    
      // Create an ArcGIS Online portal item using the item ID.
      final portalItem = PortalItem.withPortalAndItemId(
        portal: Portal.arcGISOnline(),
        itemId: 'acc027394bc84c2fb04d1ed317aac674',
      );
    
    }
  2. Define a final map variable and set its value to an instance of ArcGISMap using the PortalItem.

    main.dart > onMapViewReady()
    Use dark colors for code blocks
    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
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
        // Create an ArcGIS Online portal item using the item ID.
        final portalItem = PortalItem.withPortalAndItemId(
          portal: Portal.arcGISOnline(),
          itemId: 'acc027394bc84c2fb04d1ed317aac674',
        );
    
        // Define an ArcGIS map variable to hold on to the web map.
        final map = ArcGISMap.withItem(portalItem);
    
  3. Set the map to the ArcGISMapViewController's arcGISMap property.

    main.dart > onMapViewReady()
    Use dark colors for code blocks
    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
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
        // Define an ArcGIS map variable to hold on to the web map.
        final map = ArcGISMap.withItem(portalItem);
    
        // Set the map to the map view controller's ArcGIS map property.
        _mapViewController.arcGISMap = map;
    
  4. Make sure you have an Android emulator, iOS simulator or physical device configured and running.

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

You should see a map of the stormwater network within Naperville, IL, USA. Pinch, drag, and double-tap the map view to explore the map. Leave the application running while you move into the next section to continue with the tutorial.

Specify an area of the web map to take offline

To specify an area of the web map to take offline, you will use an Envelope that will be constructed using the EnvelopeBuilder. You will then display the area on the map using a Graphic.

  1. Create an envelope builder and set its spatial reference to match the web map.

    main.dart > onMapViewReady()
    Use dark colors for code blocks
    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
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
        // Set the map to the map view controller's ArcGIS map property.
        _mapViewController.arcGISMap = map;
    
        // Create an envelope builder.
        final envelopeBuilder = EnvelopeBuilder(
          // Set the spatial reference.
          spatialReference: SpatialReference.wgs84,
        );
    
  2. Use the envelope builder to define an area to take offline.

    main.dart > onMapViewReady()
    Use dark colors for code blocks
    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
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
        // Create an envelope builder.
        final envelopeBuilder = EnvelopeBuilder(
          // Set the spatial reference.
          spatialReference: SpatialReference.wgs84,
        );
    
        // Add the lower left (Xmin, Ymin) and upper right (Xmax, Ymax)
        // coordinates to define the area to take offline.
        envelopeBuilder.xMin = -88.1526;
        envelopeBuilder.xMax = -88.1490;
        envelopeBuilder.yMin = 41.7694;
        envelopeBuilder.yMax = 41.7714;
    
        // Retrieve the new geometry from the builder.
        final offlineArea = envelopeBuilder.toGeometry();
    
  3. Display a graphic of the area to take offline.

    Use SimpleLineSymbol and SimpleFillSymbol to display a new Graphic of the offlineArea with a red outline. Add the graphic to a new GraphicsOverlay and add the new overlay to the _mapViewController.graphicsOverlays property to display it in the map view.

    main.dart > onMapViewReady()
    Use dark colors for code blocks
    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
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
        // Retrieve the new geometry from the builder.
        final offlineArea = envelopeBuilder.toGeometry();
    
        // Define a red line symbol to act as the outline
        // for the area of interest.
        final lineSymbol = SimpleLineSymbol(
          style: SimpleLineSymbolStyle.solid,
          color: Colors.red,
          width: 2,
        );
    
        // Define a fill symbol that is transparent, setting the
        // outline to the line symbol.
        final fillSymbol = SimpleFillSymbol(
          style: SimpleFillSymbolStyle.solid,
          color: Colors.transparent,
          outline: lineSymbol,
        );
    
        // Create a graphic for the area of interest using the
        // built geometry and symbol.
        final offlineAreaGraphic = Graphic(
          geometry: offlineArea,
          symbol: fillSymbol,
        );
    
        // Create a new graphics overlay.
        final areaOverlay = GraphicsOverlay();
    
        // Add the graphic to the graphics overlay.
        areaOverlay.graphics.add(offlineAreaGraphic);
    
        // Add the graphics overlay to the map view controller.
        _mapViewController.graphicsOverlays.add(areaOverlay);
    
  4. Use Flutter's hot restart to load your code changes and restart the app.

You should see a red outline on the stormwater network within Naperville, IL, USA. This indicates the area of the web map that you are going to take offline.

Download and display the offline map

You can generate and download an offline map for an area of interest using an asynchronous task. When complete, it will provide the offline map for display in your map view.

  1. Create an OfflineMapTask using the online map.

    main.dart > onMapViewReady()
    Use dark colors for code blocks
    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
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
        // Add the graphics overlay to the map view controller.
        _mapViewController.graphicsOverlays.add(areaOverlay);
    
        // Create an offline map task for the map.
        final offlineMapTask = OfflineMapTask.withOnlineMap(map);
    
  2. In onMapViewReady(), change the method signature to denote the method as asynchronous.

    main.dart
    Use dark colors for code blocks
    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
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
      void onMapViewReady() async {
    
  3. Get default parameters to generate and download the offline map. Modify them to download a read-only offline map.

    main.dart > onMapViewReady()
    Use dark colors for code blocks
    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
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
        // Create an offline map task for the map.
        final offlineMapTask = OfflineMapTask.withOnlineMap(map);
    
        // Create parameters specifying the region to take offline
        // using the graphic's geometry. Set the update mode to
        // no updates to avoid the overhead of maintaining the
        // metadata required when synchronizing edits.
        final parameters = await offlineMapTask
              .createDefaultGenerateOfflineMapParameters(
                areaOfInterest: offlineArea,
              )
          ..updateMode = GenerateOfflineMapUpdateMode.noUpdates;
    
  4. Set a download location for the offline map.

    main.dart > onMapViewReady()
    Use dark colors for code blocks
    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
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
        // Create parameters specifying the region to take offline
        // using the graphic's geometry. Set the update mode to
        // no updates to avoid the overhead of maintaining the
        // metadata required when synchronizing edits.
        final parameters = await offlineMapTask
              .createDefaultGenerateOfflineMapParameters(
                areaOfInterest: offlineArea,
              )
          ..updateMode = GenerateOfflineMapUpdateMode.noUpdates;
    
        // Prepare an empty directory to store the offline map.
        final documentsUri = (await getApplicationDocumentsDirectory()).uri;
        final downloadDirectoryUri = documentsUri.resolve('offline_map');
        // If the download directory already exists we delete.
        // If this is undesirable, use a unique identifier for the downloadDirectoryUri
        // such as appending a timestamp.
        if (Directory.fromUri(downloadDirectoryUri).existsSync()) {
          Directory.fromUri(downloadDirectoryUri).deleteSync(recursive: true);
        }
        Directory.fromUri(downloadDirectoryUri).createSync();
    
    
  5. Create a new GenerateOfflineMapJob using the parameters and downloadDirectoryUri.

    main.dart > onMapViewReady()
    Use dark colors for code blocks
    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
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
        // Prepare an empty directory to store the offline map.
        final documentsUri = (await getApplicationDocumentsDirectory()).uri;
        final downloadDirectoryUri = documentsUri.resolve('offline_map');
        // If the download directory already exists we delete.
        // If this is undesirable, use a unique identifier for the downloadDirectoryUri
        // such as appending a timestamp.
        if (Directory.fromUri(downloadDirectoryUri).existsSync()) {
          Directory.fromUri(downloadDirectoryUri).deleteSync(recursive: true);
        }
        Directory.fromUri(downloadDirectoryUri).createSync();
    
    
        // Create a job to generate the offline map passing in
        // the parameters and download directory.
        final generateOfflineMapJob = offlineMapTask.generateOfflineMap(
          parameters: parameters,
          downloadDirectoryUri: downloadDirectoryUri,
        );
    
  6. Add code to listen for when the generate offline map job completes or fails and to track the percent complete as the job runs. Add a try/catch block to handle exceptions.

    main.dart > onMapViewReady()
    Use dark colors for code blocks
    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
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
        // Create a job to generate the offline map passing in
        // the parameters and download directory.
        final generateOfflineMapJob = offlineMapTask.generateOfflineMap(
          parameters: parameters,
          downloadDirectoryUri: downloadDirectoryUri,
        );
    
        // Listen for status updates as the generate offline map
        // job runs.
        generateOfflineMapJob.onStatusChanged.listen((jobStatus) {
          try {
    
            // See next step.
    
          } on ArcGISException catch (e) {
            debugPrint('Error generating offline map: ${e.message}');
          }
        });
    
  7. If the job succeeds, set the arcgisMap property on the map view controller with the offline map result. If it fails, print out a message. If the job is running, print the percent complete.

    main.dart > onMapViewReady() > try{}
    Use dark colors for code blocks
    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
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
        // Listen for status updates as the generate offline map
        // job runs.
        generateOfflineMapJob.onStatusChanged.listen((jobStatus) {
          try {
    
            // If the job succeeds, show the offline map.
            if (generateOfflineMapJob.status == JobStatus.succeeded) {
              // Retrieve the offline map.
              final result = generateOfflineMapJob.result;
    
              if (result == null) return;
    
              // Set the map view controller's ArcGIS map to the offline map.
              _mapViewController.arcGISMap = result.offlineMap;
    
              debugPrint('Generate offline map: Complete');
            } else if (generateOfflineMapJob.status == JobStatus.failed) {
              // If the job fails, print out the error message.
              debugPrint(
                'Unable to generate a map for that area: ${generateOfflineMapJob.error?.message}',
              );
            } else {
              // Otherwise, get the progress and report it.
              final percentComplete = generateOfflineMapJob.progress;
    
              debugPrint('Percent complete: $percentComplete%');
            }
    
          } on ArcGISException catch (e) {
            debugPrint('Error generating offline map: ${e.message}');
          }
        });
    
  8. Start the generate offline map job.

    main.dart > onMapViewReady()
    Use dark colors for code blocks
    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
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
          } on ArcGISException catch (e) {
            debugPrint('Error generating offline map: ${e.message}');
          }
        });
    
        // Start the generate offline map job.
        generateOfflineMapJob.start();
    
      }
    
  9. Hot restart your app.

You should see an offline map for the specified area of the stormwater network within Naperville, IL, USA. Remove your network connection and you will still be able to pinch, drag, and double-tab the map view to explore this offline 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.

Set developer credentials in the solution

To allow your app users to access ArcGIS location services, 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 token.

    main.dart
    Use dark colors for code blocks
    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
    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:

    Use dark colors for code blocksCopy
    1
    flutter pub upgrade
  2. Run:

    Use dark colors for code blocksCopy
    1
    dart run arcgis_maps install
  3. Make sure you have an Android emulator, iOS simulator or physical device configured and running.

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

You should see an offline map for the specified area of the stormwater network within Naperville, IL, USA. Remove your network connection and you will still be able to pinch, drag, and double-tab the map view to explore this offline map.

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