Hello Map¶
Setup¶
Prerequisites¶
Build and Run¶
Navigate to the hello_map
directory within the Flutter examples directory. This is the directory name for this example project.
Note - the gem_kit
directory containing the Maps SDK for Flutter
should be in the plugins
directory of the example, e.g.
example_pathname/plugins/gem_kit
- see the environment setup guide above.
Replace example_pathname
with the actual example path name,
such as address_search
Download project dependencies:
flutter upgrade
run the following terminal commands in the project directory,
where the pubspec.yaml
file is located:
flutter clean
flutter pub get
Run the example:
First, verify that the ANDROID_SDK_ROOT
environment variable
is set to the root path of your android SDK.
In android/build.gradle
add the maven {}
block as shown,
within the allprojects {} block
, for both debug and release builds,
without the line numbers, those are for reference:
1allprojects {
2 repositories {
3 google()
4 mavenCentral()
5 maven {
6 url "${rootDir}/../plugins/gem_kit/android/build"
7 }
8 }
9}
in android/app/build.gradle
within the android {}
block, in the defaultConfig {}
block,
the android SDK version minSdk
must be set as shown below.
Additionally, for release builds, in android/app/build.gradle
,
within the android {}
block, add the buildTypes {}
block as shown:
Replace example_pathname
with the actual example pathname, such as center_coordinates
1android {
2 defaultConfig {
3 applicationId "com.magiclane.gem_kit.examples.example_pathname"
4 minSdk 21
5 targetSdk flutter.targetSdk
6 versionCode flutterVersionCode.toInteger()
7 versionName flutterVersionName
8 }
9 buildTypes {
10 release {
11 minifyEnabled false
12 shrinkResources false
13
14 // TODO: Add your own signing config for the release build.
15 // Signing with the debug keys for now, so `flutter run --release` works.
16 signingConfig signingConfigs.debug
17 }
18 }
19}
Then run the project:
flutter run --debug
flutter run --release
In the ios/Podfile
configuration text file, at the top, set the minimum ios
platform to 13 like this:
platform :ios, '13.0'
Then run the project:
flutter run --debug
flutter run --release
How It Works¶
The following code demonstrates the main components of the “Hello Map” example:
1import 'package:flutter/material.dart';
2import 'package:gem_kit/core.dart';
3import 'package:gem_kit/map.dart';
4
5Future<void> main() async {
6 const projectApiToken = String.fromEnvironment('GEM_TOKEN');
7
8 await GemKit.initialize(appAuthorization: projectApiToken);
9
10 runApp(const MyApp());
11}
12
13class MyApp extends StatelessWidget {
14 const MyApp({super.key});
15
16 @override
17 Widget build(BuildContext context) {
18 return const MaterialApp(
19 debugShowCheckedModeBanner: false,
20 title: 'Hello Map',
21 home: MyHomePage(),
22 );
23 }
24}
In the above code, the MaterialApp is initialized with the GemKit authorization token. The main widget, MyApp, serves as the root of the application, which will display the interactive map.
Map Display and Clean Up¶
The following code outlines the main page widget, which displays the map and handles resource clean-up:
1class MyHomePage extends StatefulWidget {
2 const MyHomePage({super.key});
3
4 @override
5 State<MyHomePage> createState() => _MyHomePageState();
6}
7
8class _MyHomePageState extends State<MyHomePage> {
9 @override
10 void dispose() {
11 GemKit.release();
12 super.dispose();
13 }
14
15 @override
16 Widget build(BuildContext context) {
17 return Scaffold(
18 appBar: AppBar(
19 backgroundColor: Colors.deepPurple[900],
20 title: const Text('Hello Map', style: TextStyle(color: Colors.white)),
21 ),
22 body: const GemMap(),
23 );
24 }
25}