# Troubleshooting

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

Fix the errors Dart and Flutter developers hit first with the Mountaya SDK: undefined server names, empty keys, blank maps, platform floors and refused writes.

The failures developers meet first with the Dart SDK, each with its fix.

## `SecretCredential` is not defined in my app

`SecretCredential` and `constructWebhookEvent` exist on the Dart VM only. A Flutter build leaves them out, so a secret key cannot ship inside an app. Mint session tokens and verify webhooks on your server, and give the app a publishable key with a [`SessionTokenEngine`](https://docs.mountaya.com/en/sdks/dart/authentication.md#rotate).

- Both names sit behind conditional exports that leave them out wherever `dart:ui` is available: every Flutter build for Android and iOS, debug and release. A `dart test` or `dart run` of the same code on the VM sees them.
- A package shared by an app and a server keeps its server code in a library only the server imports.

## The client throws `ConfigurationException` as it is built

The key is empty or misprefixed. `String.fromEnvironment` answers `''` when the build was not given the value:

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

Check that `.env` holds `MOUNTAYA_PUBLISHABLE_KEY=pk_…`, and rebuild: the value is compiled in.

- The local check is the prefix (`pk_`, `sk_`), never the length; a well-formed wrong key answers `401` instead. Every key, token, language and header must be printable ASCII.
- A hot reload does not re-read `--dart-define`: stop the app and run it again.
- `.publishable(key: '')` and `SecretCredential('')` are refused alike. Trail checks for an empty key first and shows a notice in place of the map.

## Search or a Data API call answers 401

The Data API answers a publishable key only beside a live session token. A token held as a value expires in minutes: give the client a `SessionTokenEngine`, which mints again before it does:

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

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

// Your app's call to your session route, as Authentication in the SDK shows.
Future<rest_schema.Session> mintSession() =>
    throw UnimplementedError('Ask your server for a session.');

final mountaya = Mountaya(
  credential: .publishable(
    key: publishableKey,
    sessionToken: .source(SessionTokenEngine(mint: mintSession)),
  ),
);
await mountaya.close();
```

- With no session token at all, the client refuses the call locally as `ConfigurationException` before it is sent; its `cause` is the mint's failure where a session engine failed to mint. An expired `.value(...)` token reaches the API and answers `401`, an `AuthenticationException`.
- Every Data API operation, every `management` operation and every `studio-embedded` operation requires one. A search box with no session shows its branches as failed and hands the error to `onError`.

## The map is blank in a release build on Android

Flutter's template grants the network to debug builds only. Declare it in `android/app/src/main/AndroidManifest.xml`:

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

- Without it, every request of a release build fails: the map's tiles as `MapEventFailure`, the client's calls as `ConnectionException`.
- Plain HTTP (a session server at `http://10.0.2.2:8787`) is allowed in a debug build alone; a release build needs HTTPS.

## The build refuses the iOS or Android version

The map plugin needs iOS 15.5 and Android API level 24, the navigation plugin iOS 14.0 and API level 24. Raise the Runner target's **Minimum Deployments** in Xcode, `platform :ios` in `ios/Podfile`, and `minSdk` in `android/app/build.gradle.kts`, as [Install and set up](https://docs.mountaya.com/en/sdks/dart/install.md#platform-setup) shows.

- The Dart and Flutter floors are Dart 3.12 and Flutter 3.44 for the plugins, Dart 3.10 for the pure packages; `pub get` names the one the app falls short of.
- No web or desktop build is published: a Flutter web, macOS, Windows or Linux target resolves the pure packages but the plugins do not run there, and `MapView` draws nothing.

## `MapEngine` refuses my client

A map takes a publishable key alone, with a session token as a value or a `SessionTokenEngine`, or a share token. It refuses a secret key, and a session token read by a function, with `ConfigurationException`. Build the map's client with `.source(sessions)` or `.value(token)`.

- The map hands MapLibre's request hook its headers as values set between requests, since a platform channel cannot answer MapLibre's loader at each request. A `.function(...)` token would have to be read at every tile.
- A secret key authenticates no route a map fetches.

## The map stays empty

`map.state.isAccessRequired` is `true` and `events()` tells a `MapEventAccessRefused`. The key lacks a scope: `tiles` draws the map, `publishing` reads an itinerary. Add the scope under **Organization → API keys** in the [Mountaya app](https://app.mountaya.com/api-keys).

- A `401` is an unknown key or an expired token; a `402` a product the organization lacks; a `403` a missing scope. The status is on the event.
- The refusal stands until a tile of the refused source loads, told once as `MapEventAccessRestored`, so a notice raised on `isAccessRequired` comes down by itself.
- An app's own `setHttpHeaders` or `setCustomHeaders` on `maplibre_gl` takes the request hook off, and the map's requests leave without a credential. On iOS, a network delegate that answers its own session does the same.

## A panel opens under the controls

A panel opens in the nearest `Overlay`. A `Navigator` provides one; under a bare `WidgetsApp` with a `builder`, wrap the screen in one:

```dart
import 'package:flutter/widgets.dart';

// A screen of yours that holds MapView and MapControls.
Widget withOverlay(Widget screen) => WidgetsApp(
  color: const Color(0xff1c7ed6),
  builder: (context, _) => Overlay(
    initialEntries: [OverlayEntry(builder: (context) => screen)],
  ),
);
```

## A write answers 401

A write to an itinerary, a collection or a zone acts as a member. Mint its token with `user_id` and `surface: rest_schema.SessionSurface.studioEmbedded`, beside a key carrying the `studio-embedded` scope, as [Act as a member](https://docs.mountaya.com/en/sdks/dart/authentication.md#act-as-member) shows.

- The client refuses the write locally with `ConfigurationException` where a session engine or a minted session says the token was minted without `user_id`. For a `.value(...)` token it cannot tell, and the API answers `401`.
- A `402` on the mint: the organization lacks Embedded Studio. A `403`: the key lacks `studio-embedded`.
- A `management` write takes a key carrying `management` alone and a token naming an owner or admin ([manage an organization](https://docs.mountaya.com/en/sdks/dart/admin.md)).

## A call answers 402

A `BillingException` means your agreement does not cover the call, or a payment is missing. Its message says which: change the product with Mountaya, or add a payment method in your billing settings. Code cannot fix it.

- A `402` is always a `BillingException`, whatever its entry says; the entry's code is `ApiErrorCode.paymentRequired`. The API checks the product before the key's scopes, so a key carrying a scope whose product the organization lacks gets `402`, not `403`.
- On the Data API a `402` also refuses a self-serve organization with no payment method on file, or with invoices its payment method could not pay.
- A mint for `studio-embedded` answers `402` where the organization lacks Embedded Studio.
- The client never retries a `402`. See [errors](https://docs.mountaya.com/en/apis/conventions/errors.md#payment-errors).

## A webhook delivery never verifies

`constructWebhookEvent` throws `WebhookSignatureException`, and its `reason` says why. A `signature` reason means the body changed or the secret is wrong: pass the body exactly as it arrived, and the secret of the endpoint the delivery was sent to. A `timestamp` reason means your server's clock is off.

- Reasons: `missingHeader` (no `Mountaya-Signature`), `malformedHeader`, `signature` (no `v1` of the header matches), `timestamp` (the signature verifies, made further than `tolerance`, 300 seconds by default, from your clock either way).
- A body parsed as JSON and encoded again is other bytes. Read the request's bytes before any parser: a `Uint8List` or `List<int>`, or the `String` of exactly what arrived.
- The secret is `whsk_` and 64 hex characters, one per endpoint, shown once at creation and revealed again in the Mountaya app. During a rotation's overlap either secret verifies.
- Check your code against the [test vectors](https://docs.mountaya.com/en/webhooks/signatures.md#test-vectors), `now:` pinned to each case's time ([test your receiver](https://docs.mountaya.com/en/sdks/dart/webhooks.md#test)).

## Navigation says nothing

The engine speaks only through the voice you hand it, and only the instructions your `words` function answers. Hand `DeviceNavigationEngine(voice:)` a `SpeechNavigationVoice`, give it an `onError`, and answer a sentence for each key you use, as [Speak the prompts](https://docs.mountaya.com/en/sdks/dart/navigation.md#voice) shows.

- The default voice is `InertNavigationVoice`, which says nothing. An instruction whose `words` answers `null` is not said.
- `SpeechException` kinds on `onError`: `engineUnavailable` (Android's speech engine did not start; `prepare()` learns it as it completes) and `audioRefused` (the platform refused a sentence's audio, said all the same over other apps' audio, or unheard).
- On iOS a voice is heard with the screen off only where the app declares `audio` beside `location` under `UIBackgroundModes`; without it a source started with `backgroundUpdates: true` tells `audioUndeclared`.
- A maneuver is said once per route, 50 m before it, only while the traveller is on the route: an `offRoute` traveller hears nothing until a `reroute`.

## No cut-off times appear

The profile, the waypoint table and the card write a cut-off only through your `formatCutoffAt`, in the device's time zone. Read it with `deviceTimeZone()` and write with `formatDateTime`, as [Show services and cut-offs](https://docs.mountaya.com/en/sdks/dart/elevation-profile.md#places) shows.

- `deviceTimeZone()` answers `null` where no native side answers (a VM test) or the device names no zone; hand no writer then. A test states one with `withDeviceTimeZone`.

## Navigation reads no position

`DeviceLocationSource` reads only while your app holds location access at full accuracy, and never asks for it. Ask in your own flow, declare the purpose string and permissions ([use the device's location](https://docs.mountaya.com/en/sdks/dart/navigation.md#location)), then call `recheckPermission()`.

- A traveller who allowed only an approximate location is read nowhere. Hand the source an `onError` to hear `permissionRevoked`, `providerDisabled`, `noProvider`, `platformFailed`, `backgroundUndeclared` and `audioUndeclared`; with none, failures are dropped, a debug build writing each to the console once.
- A position iOS cannot fix yet, indoors, is never told: it keeps trying.

## Next steps

- [Errors and retries](https://docs.mountaya.com/en/sdks/dart/errors.md): Every error class and its status.
- [Testing](https://docs.mountaya.com/en/sdks/dart/testing.md): Reproduce a failure in a test.
