# Install and set up

> Canonical URL: https://docs.mountaya.com/en/sdks/dart/install/
> Last updated: 2026-11-27
> Rules for agents: https://docs.mountaya.com/llms.txt#rules-for-agents

Add the Mountaya pub packages, set the Android and iOS floors the plugins need, and read your publishable key with --dart-define-from-file.

The Dart SDK is five pub packages released together. A Flutter app adds the ones it draws with, and a Dart server adds the pure ones.

## Install the packages

In a Flutter app that shows a map:

```bash
flutter pub add mountaya_client mountaya_geo mountaya_elements_flutter
```

Add `mountaya_navigation_flutter` beside them for turn-by-turn navigation. On a Dart server or in a command-line tool:

```bash
dart pub add mountaya_client mountaya_admin
```

`mountaya_admin` mints session tokens, manages your organization and verifies webhooks. Only a server adds it.

- The five packages are published to pub.dev at one version, and each names its siblings at exactly that version, so `pub add` resolves them together. Add every Mountaya package at the same version, `0.1.0` today.
- A server or tool resolves no Flutter, no MapLibre and no native code: `mountaya_client`, `mountaya_admin` and `mountaya_geo` are pure Dart.
- An app never adds `mountaya_admin`. A Flutter app that follows routes and draws no map adds `mountaya_client`, `mountaya_geo` and `mountaya_navigation_flutter`, and resolves no `maplibre_gl`.
- Never declare `maplibre_gl`, Pigeon, or a location or speech plugin yourself: the packages' own native sides do that work. The one exception is an app that reaches MapLibre's controller through `MapView(onReady:)`; it declares `maplibre_gl` within the range `mountaya_elements_flutter` names (`^0.28.0`), and pub resolves the one copy both use.
- No web or desktop build is published. A Flutter web or desktop target gets nothing from these packages.

## Set up the platform

The map plugin needs iOS 15.5 and Android API level 24. The navigation plugin alone needs iOS 14.0. Raise the floors your app sets lower:

```kotlin
// android/app/build.gradle.kts
android {
    defaultConfig {
        minSdk = 24
    }
}
```

On iOS, set **Minimum Deployments** of the Runner target to 15.5 in Xcode, and `platform :ios, '15.5'` in `ios/Podfile` if your app uses CocoaPods.

A release build on Android reaches the network only with the `INTERNET` permission in `android/app/src/main/AndroidManifest.xml`:

```xml
<uses-permission android:name="android.permission.INTERNET" />
```

An app that locates its reader or navigates also declares location access. [Navigation](https://docs.mountaya.com/en/sdks/dart/navigation.md#location) shows the lines.

- Floors: `mountaya_elements_flutter` Dart 3.12, Flutter 3.44, iOS 15.5, Android API level 24 (`maplibre_gl`'s floors, since MapLibre Native draws the map). `mountaya_navigation_flutter` Dart 3.12, Flutter 3.44, iOS 14.0, Android API level 24. The pure packages Dart 3.10 and no platform floor. pub, Xcode, CocoaPods and Gradle each name the floor an app falls short of.
- On iOS each plugin is a Swift package, which Flutter builds by default, and a CocoaPods pod for an app that turned Swift Package Manager off. The Swift package states its floor (`.iOS("15.5")`, `.iOS("14.0")`), so Xcode refuses a lower Runner deployment target.
- Flutter's app template declares `INTERNET` in the debug and profile manifests only. Without it in `main`, a release build draws no tiles and every call fails as a `ConnectionException`. Trail declares it in its main manifest.
- Neither plugin declares a location permission. Asking for location access is the app's: `NSLocationWhenInUseUsageDescription` in `ios/Runner/Info.plist`, and `ACCESS_FINE_LOCATION` beside `ACCESS_COARSE_LOCATION` in the Android manifest. Background reading adds `location` (and `audio` for a voice) under `UIBackgroundModes`, and on Android `ACCESS_BACKGROUND_LOCATION` or a foreground service of type `location` the app runs itself.
- The navigation plugin's own Android manifest declares the `TTS_SERVICE` query Android 11 and later need to bind text to speech; the app adds nothing for speech.
- On Android, the map's requests go through an `OkHttpClient` of your own where you set `MountayaElementsPlugin.okHttpClient` in `MainActivity.configureFlutterEngine`, before the first map shows. On iOS, set pinning, caching or timeouts on `MLNNetworkConfiguration.sharedManager.sessionConfiguration`. A network delegate that answers its own session leaves the map's requests without a credential.

## Add your key

Put your publishable key in a `.env` file that git ignores:

```text
MOUNTAYA_PUBLISHABLE_KEY=pk_your_publishable_key
```

Read it where the compiler sees it, and run with `flutter run --dart-define-from-file=.env`:

```dart
import 'package:mountaya_client/mountaya_client.dart';

// Compiled in from --dart-define-from-file=.env.
const publishableKey = String.fromEnvironment('MOUNTAYA_PUBLISHABLE_KEY');

final mountaya = Mountaya(credential: .publishable(key: publishableKey));
await mountaya.close();
```

A server reads its keys from the environment:

```dart
import 'dart:io';

import 'package:mountaya_client/mountaya_client.dart';

final server = Mountaya(
  credential: SecretCredential(Platform.environment['MOUNTAYA_SECRET_KEY'] ?? ''),
);
await server.close();
```

Create both keys under **Organization → API keys** in the [Mountaya app](https://app.mountaya.com/api-keys).

- `String.fromEnvironment` is read at compile time: a release build carries the value it was built with. The same holds for `flutter build apk --dart-define-from-file=.env`. Trail reads `MOUNTAYA_PUBLISHABLE_KEY`, `MOUNTAYA_ITINERARY_ID` and `MOUNTAYA_SESSION_URL` this way, each empty value read as none.
- A key is its prefix followed by 32 lowercase hex characters. The client checks the prefix only: `pk_` for a publishable key, `sk_` for a secret key. An empty or misprefixed key throws `ConfigurationException` where the client is built; a well-formed wrong key reaches the API and answers `401`. A credential prints each key and token by its prefix alone (`PublishableCredential(pk_…)`), so a log never holds one.
- Every key, token, language and header a request carries must be printable ASCII; anything else is a `ConfigurationException` before the request leaves.
- The publishable key ships in the app; it needs the scopes of what the app does: `tiles` to draw the map, `publishing` to read a published itinerary, `data` for search and the Data API. Never give an app's key `management`.
- The secret key (`sk_…`) mints session tokens and nothing else. It stays on a server: `SecretCredential` does not exist in a Flutter build.

## Import the right package

| Import | For |
| --- | --- |
| `package:mountaya_client/mountaya_client.dart` | `Mountaya`, credentials, errors, streams |
| `package:mountaya_client/rest_schema.dart` | Map Studio API types, as `rest_schema` |
| `package:mountaya_client/data_schema.dart` | Data API types, as `data_schema` |
| `package:mountaya_client/tile_schema.dart` | Tile API types, as `tile_schema` |
| `package:mountaya_admin/mountaya_admin.dart` | `admin`, webhook verification, on a server |
| `package:mountaya_geo/mountaya_geo.dart` | Units, formatting, profiles, search rules |
| `package:mountaya_navigation_flutter/mountaya_navigation_flutter.dart` | `DeviceNavigationEngine` and its voice |
| `package:mountaya_elements_flutter/mountaya_elements_flutter.dart` | `MapEngine`, `MapView` and every widget |

The secret key and `mountaya_admin` belong on a server only.

- The three schema libraries are imported under a prefix (`as rest_schema`, `as data_schema`, `as tile_schema`), since many names exist on more than one API. `package:mountaya_admin/admin_schema.dart` holds the admin unit's own types, imported `as admin_schema`. Names are the contract's, verbatim (`activity_id`, `itinerary_id`).
- Every wire enum is an open vocabulary: an extension type with a constant per value, named in lowerCamelCase (`data_schema.ActivitySlug.hikingAndTrail`, `rest_schema.TileSourceSize.size512`, `data_schema.ManeuverType.continue_`). A value a later contract adds decodes in an older build, so a `switch` over one keeps a default.
- A `format: date-time` value is a UTC `DateTime`; a web address is a `Url`, the text the answer sent.
- `schemaVersion` names the contract tag a build was printed from (`v0.9.0`) and `modelDigest` the exact files.

## Next steps

- [Quickstart](https://docs.mountaya.com/en/sdks/dart/quickstart.md): A map with an itinerary in a Flutter app.
- [Server quickstart](https://docs.mountaya.com/en/sdks/dart/quickstart-server.md): Mint a session token and call the Data API.
