# Quickstart

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

Show a Mountaya map with the Tour du Mont-Blanc on it in a Flutter app for Android and iOS.

A Flutter app for Android and iOS that shows a topographic map and draws the Tour du Mont-Blanc on it.

## Before you start

You need Flutter 3.44 or newer, an Android emulator or an iOS 15.5 simulator, and a publishable key with the `tiles` and `publishing` scopes from **Organization → API keys** in the [Mountaya app](https://app.mountaya.com/api-keys).

## Install

```bash
flutter create trail && cd trail
flutter pub add mountaya_client mountaya_geo mountaya_elements_flutter
```

Then raise the app's floors to iOS 15.5 and Android API level 24, as [Install and set up](https://docs.mountaya.com/en/sdks/dart/install.md#platform-setup) shows.

## Add your key

Create `.env` at the project's root, and add it to `.gitignore`:

```text
MOUNTAYA_PUBLISHABLE_KEY=pk_your_publishable_key
```

## Show the map

Replace `lib/main.dart` with this:

```dart
import 'dart:async';

import 'package:flutter/widgets.dart';
import 'package:mountaya_client/mountaya_client.dart';
import 'package:mountaya_elements_flutter/mountaya_elements_flutter.dart';

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

void main() => runApp(
  WidgetsApp(
    color: const Color(0xff1c7ed6),
    builder: (context, _) => const TrailMap(),
  ),
);

class TrailMap extends StatefulWidget {
  const TrailMap({super.key});

  @override
  State<TrailMap> createState() => _TrailMapState();
}

class _TrailMapState extends State<TrailMap> {
  final mountaya = Mountaya(credential: .publishable(key: publishableKey));
  late final map = MapEngine(mountaya);

  @override
  void initState() {
    super.initState();
    unawaited(map.setTerrain());
  }

  @override
  void dispose() {
    map.close();
    unawaited(mountaya.close());
    super.dispose();
  }

  @override
  Widget build(BuildContext context) => MapView(engine: map);
}
```

`MapEngine` holds what the map shows, and `MapView` draws it. Your `State` makes both and closes them.

## Draw an itinerary

Replace `TrailMap` with this version. The camera frames the itinerary once it is drawn:

```dart
import 'dart:async';

import 'package:flutter/widgets.dart';
import 'package:mountaya_client/mountaya_client.dart';
import 'package:mountaya_elements_flutter/mountaya_elements_flutter.dart';
import 'package:mountaya_geo/mountaya_geo.dart';

const publishableKey = String.fromEnvironment('MOUNTAYA_PUBLISHABLE_KEY');

class TrailMap extends StatefulWidget {
  const TrailMap({super.key});

  @override
  State<TrailMap> createState() => _TrailMapState();
}

class _TrailMapState extends State<TrailMap> {
  final mountaya = Mountaya(credential: .publishable(key: publishableKey));
  late final map = MapEngine(mountaya);

  @override
  void initState() {
    super.initState();
    unawaited(_show());
  }

  Future<void> _show() async {
    await map.setTerrain();
    await map.setItinerary(
      '0b6d1a4e-6d3f-4f7a-9c2e-1f0a5b8c3d21',
      fit: const CameraFit(padding: PixelPadding.all(48)),
    );
  }

  @override
  void dispose() {
    map.close();
    unawaited(mountaya.close());
    super.dispose();
  }

  @override
  Widget build(BuildContext context) => MapView(engine: map);
}
```

## Run it

```bash
flutter run --dart-define-from-file=.env
```

The map opens on the Tour du Mont-Blanc, with the Mountaya watermark in its top-left corner.

- The sample app Trail, under `examples/trail` in the SDK repository, is the complete version of this quickstart: controls, search, the profile, the tables and navigation. Copy `examples/trail/.env.example` to `.env`, then `flutter run --dart-define-from-file=.env` from `examples/trail`.
- `setTerrain()` shows the first terrain of the Tile API's catalogue, light until `setTerrainVariant(tile_schema.TerrainVariant.dark)`. `setTerrain('<slug>')` names another. A catalogue that cannot be read fails the future and is told on `events()` as `MapEventAccessRefused` or `MapEventFailure`; Trail catches `MountayaException` and `MapException` around it.
- `setItinerary(id, fit:)` draws one itinerary by id in its own slot; a later call replaces it, and one that answers after a later call answers `false`. Pass `signal:` an `AbortSignal` to withdraw it. `clearItinerary()` removes it.
- The key needs `tiles` to draw the map and `publishing` for a published itinerary. A refused key shows as `map.state.isAccessRequired` and a `MapEventAccessRefused` event; see [show a map](https://docs.mountaya.com/en/sdks/dart/map.md#errors).
- Every request MapLibre makes for the map (style, tiles, sprites, glyphs) carries the client's credential, its language and `X-Mountaya-Client`, and only to the Tile API's host.
- The watermark shows unless the organization holds white label; the map reads that once per key.
- With no key defined, `String.fromEnvironment` answers `''`, which `Mountaya` refuses with `ConfigurationException` where it is built. Trail checks for an empty key first and shows a notice in place of the map.
- The sample draws with `package:flutter/widgets.dart` and a `WidgetsApp`: no widget of the SDK reads a Material or Cupertino theme, and Flutter deprecates `package:flutter/material.dart` from 3.47 in favour of `package:material_ui`. An app on either design system hosts `MapView` the same way; `MapControls`' panels need the `Overlay` a `Navigator` provides ([controls](https://docs.mountaya.com/en/sdks/dart/controls.md#stack)).
- Dart has no deinitializer and `MapView` never closes the engine it is handed: the `State` that made the engine closes it in `dispose`, and the client after it.

## Next steps

- [Show a map](https://docs.mountaya.com/en/sdks/dart/map.md): The camera, events, layers and waypoints.
- [Controls and panels](https://docs.mountaya.com/en/sdks/dart/controls.md): Zoom, layers, points of interest and units.
