Skip to content

Environment Setup - Flutter Examples

In this guide you will learn how to set up your environment to run the Flutter examples.

Create Your Account

First, create your Magic Lane account and get your API key token. See the Getting Started guide.

Install Flutter

Follow the instructions to install Flutter by visiting the official documentation:

Flutter Install

Download Examples

Download the Flutter examples ZIP file or clone the repository using git.

Maps SDK Examples for Flutter

After downloading the examples, you will have a file like this:

maps-sdk-examples-for-flutter-master.zip

Download the SDK

Download the Maps SDK for Flutter:

Maps SDK for Flutter

Extract the SDK

Unzip the downloaded file and look for the ``gem_kit``folder. This is the Flutter SDK.

Move the SDK Directory

Move the gem_kit``directory into the ``plugins subdirectory of the example you wish to run, such as hello_map/plugins.

Build and Run

Now that Flutter is installed, and you have moved the ``gem_kit``directory to the plugins directory of the example you want to run, you are ready to build and run the example.

Hello map - example Flutter screenshot

Run the example:

flutter run

Set the API Key Token

In the main.dart source code file, in the main() function, the API TOKEN is set.

When you run your Flutter app, you can pass the API token as a parameter: flutter run --dart-define=GEM_TOKEN="your_actual_api_token"

Future<void> main() async {
  const projectApiToken = String.fromEnvironment('GEM_TOKEN');
  await GemKit.initialize(appAuthorization: projectApiToken);
  runApp(const MyApp());
}

Or replace the main method:

Future<void> main() async {
  const String projectApiToken = "YOUR_API_TOKEN"
  await GemKit.initialize(appAuthorization: projectApiToken);
  runApp(const MyApp());
}

Alternatively, you can pass the token to the appAuthorization parameter of GemMap to authorize the application.

const projectApiToken = String.fromEnvironment('GEM_TOKEN');

GemMap(appAuthorization: projectApiToken);