Learn how to display a map from a mobile map package (MMPK).

In this tutorial you will display a fully interactive map from a mobile map package (MMPK). The map contains a basemap layer and data layers and does not require a network connection.
Prerequisites
Before starting this tutorial:
-
You need an ArcGIS Location Platform or ArcGIS Online account.
-
Your system meets the system requirements.
-
You need an IDE for Flutter - we recommend VS Code.
Develop or Download
You have two options for completing this tutorial:
Option 1: Develop the code
-
Open the project you created by completing the Display a map tutorial.
-
Continue with the following instructions to display a map from a mobile map package (.mmpk) file.
Add a mobile map package
Add a mobile map package (.mmpk) for distribution with your app.
-
Create or download the
Mahou
mobile map package. Complete the Create a mobile map package tutorial to create the package yourself. Otherwise, download the solution file: MahouRivieraTrails.mmpk.Riviera Trails.mmpk -
In VS Code, create a new folder:
assets
. Place the mobile map package file within this folder, for example:assets/
.Mahou Riviera Trails.mmpk -
Open
pubspec.yaml
and add an asset entry for the mobile map package.pubspec.yamlUse dark colors for code blocks # ... flutter: uses-material-design: true assets: - assets/MahouRivieraTrails.mmpk
Import additional library and packages
As part of this tutorial, you will need to access resources packaged with the app. You will add core dependencies: dart
and services.dart
. dart
provides access to an API to deal with files and directories, while services.dart
will allow you to access the mobile map package file that is packaged with the app. In addition, you'll add the path
package to access local files on the device.
-
In VS Code, double-click
lib\main.dart
to open the file. -
From the menu bar, select View > Terminal to open a new terminal.
-
Add the
path
package to the project as a dependency running the following command:_provider Use dark colors for code blocks Copy flutter pub add path_provider
The
path
package provides a Flutter plugin for finding commonly used locations on the file system. You can learn more about this package on pub.dev._provider -
Import
dart
,:io services.dart
, andpath
into_provider main.dart
.main.dartUse dark colors for code blocks import 'dart:io'; import 'package:flutter/services.dart'; import 'package:path_provider/path_provider.dart'; import 'package:flutter/material.dart'; import 'package:arcgis_maps/arcgis_maps.dart'; void main() {
The
dart
library provides API to deal with files and directories. You can read more about the library here. The:io services.dart
package provides platform services, such asroot
that contains resources packaged with an app when it was built. You can learn more here.Bundle
Open the mobile map package and display a map
Select a map from the maps contained in a mobile map package and display it in a map view controller. Use the MobileMapPackage
class to access the mobile map package and load it to read its contents.
-
In
lib\main.dart
, navigate to theon
and remove all the code contained within the method.Map View Ready() main.dartUse dark colors for code blocks void onMapViewReady() { final map = ArcGISMap.withBasemapStyle(BasemapStyle.arcGISTopographic); _mapViewController.arcGISMap = map; _mapViewController.setViewpoint( Viewpoint.withLatLongScale( latitude: 34.02700, longitude: -118.80500, scale: 72000, ), ); }
-
Within
on
define a constant to hold the name of the mobile map package.Map View Ready() main.dartUse dark colors for code blocks void onMapViewReady() { const mobileMapPackageName = 'MahouRivieraTrails.mmpk'; }
-
Use
root
to load the mobile map package from the project'sBundle assets
directory and store the reference within a final variablemobile
. In addition, update theMap Package Data on
method signature to denote the method as asynchronous.Map View Ready() main.dart > onMapViewReady()Use dark colors for code blocks void onMapViewReady() async { const mobileMapPackageName = 'MahouRivieraTrails.mmpk'; // Retrieve the mobile map package from the asset bundle. final mobileMapPackageData = await rootBundle.load( 'assets/$mobileMapPackageName', ); }
-
Create a path to a temporary directory on the device to write and store the mobile map package.
main.dart > onMapViewReady()Use dark colors for code blocks // Retrieve the mobile map package from the asset bundle. final mobileMapPackageData = await rootBundle.load( 'assets/$mobileMapPackageName', ); // Path to a temporary directory on the device. // NOTE: This location is not backed up and is suitable for storing // caches of downloaded files, in this case, your mobile map package. final platformTempDir = await getTemporaryDirectory(); // Define the path on the device to the mobile map package. final pathToFile = '${platformTempDir.absolute.path}/$mobileMapPackageName'; // Create a new file using the path to the mobile map package. final mobileMapPackageFile = File(pathToFile); // Synchronously write the mobile map package to the file // on the device. mobileMapPackageFile.writeAsBytesSync( mobileMapPackageData.buffer.asUint8List(), flush: true, );
-
Create a
MobileMapPackage
with the path to the file on the device and load it.main.dart > onMapViewReady()Use dark colors for code blocks // Synchronously write the mobile map package to the file // on the device. mobileMapPackageFile.writeAsBytesSync( mobileMapPackageData.buffer.asUint8List(), flush: true, ); // Create a mobile map package using the Uri to the mobile map package file. final mobileMapPackage = MobileMapPackage.withFileUri( mobileMapPackageFile.uri, ); // Load the metadata for the mobile map package. await mobileMapPackage.load();
-
Set the map view controller's ArcGIS map property to the first map in the mobile map package.
main.dart > onMapViewReady()Use dark colors for code blocks // Load the metadata for the mobile map package. await mobileMapPackage.load(); // Check that the mobile map package is not empty. if (mobileMapPackage.maps.isNotEmpty) { // Display the first map in the mobile map package in the map // view controller. _mapViewController.arcGISMap = mobileMapPackage.maps.first; }
Run the app
Follow these steps to run the application.
-
In VS Code's terminal, run:
Use dark colors for code blocks Copy flutter pub upgrade
-
Run:
Use dark colors for code blocks Copy 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 should see a map of trail heads, trails, and parks for the area south of the Santa Monica mountains. You will be able to pinch (to zoom and rotate), 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
-
Click the
Download solution
link underSolution
and unzip the file to a location on your machine. -
Open the project in VS code.
Run the application
Follow these steps to run the application.
-
In VS Code's terminal, run:
Use dark colors for code blocks Copy flutter pub upgrade
-
Run:
Use dark colors for code blocks Copy 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 should see a map of trail heads, trails, and parks for the area south of the Santa Monica mountains. You will be able to pinch (to zoom and rotate), drag, and double-tap the map view to explore the map.