QuickStart

Introduction

The plugin was developed with Flutter version 3.24.5, it contains a sample app that allows to try the locations SDK. To perform a test it is necessary to enter correct Mobile Key. The integration and configuration include a first phase on the Flutter project and a second phase in the individual iOS and Android projects

Flutter installation

Run this command:

With Flutter:

 $ flutter pub add c4w_location_sdk_flutter

This will add a line like this to your package's pubspec.yaml (and run an implicit flutter pub get):

dependencies:
  c4w_location_sdk_flutter: ^1.0.0

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

Import it

Now in your Dart code, you can use:

import 'package:c4w_location_sdk_flutter/c4w_location_sdk_flutter.dart';

Android installation

Integration

To integrate SDK library into your Android project you need to add Cloud4Wi repository inside build.gradle

Replace x.y.z with a specific version of library that you can find here

allprojects {
    repositories {
        google()
        mavenCentral()
        ...
        maven { url = uri("https://mymavenrepo.com/repo/PzY5Lw6PNZ938XDfVtzf/") }
        ...
    }
}

dependencies {
    ...

    implementation "com.geouniq.android:c4w-location-sdk:x.y.z"
}

Configuration

The Mobile Key generated for your app when you configured your project (see here) must be provided as a string resource with name "geouniq_mobile_key".

This can be done by putting the following line into the Gradle build script of your app (build.gradle file of your app module)

defaultConfig {
    //...
    it.resValue("string", "geouniq_mobile_key", "YOUR_MOBILE_KEY")
}

It could be convenient to set a different value for the debug and the relase build types.

Note that the certificates used for the two build types are generally different, and thus their SHA1 fingerprint will be different. For this reason, you should create two different Client Apps, one for the debug and one for the release build, each with its own fingerprint (see Project Configuration). A common solution is to create two different projects, one for test and one for production, and create an Android Client App on each project, using the debug fingerprint for the test project and the release fingerprint for the production project.

buildTypes {
    release {
        //...
        it.resValue("string", "geouniq_mobile_key", "YOUR_PRODUCTION_MOBILE_KEY")
    }
    debug {
        //...
        it.resValue("string", "geouniq_mobile_key", "YOUR_TEST_MOBILE_KEY")
    }
}

Required permissions

AndroidManifest of this library requires following permissions

    
    <uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
   

iOS installation

Configuration

Mobile key

Add the following key to Info.plist file (String value) with the corresponding value (that you obtained when added your app to your project)

<key>GUMobileKey</key>
<string>'your-mobile-key'</string>

Location usage keys

  1. Add the following keys to Info.plist file (String value), the corresponding values will be shown to the user by iOS

<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>We would like to access your locations</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>We would like to access your locations</string>

Inizialize Flutter

To initialize the framework and allow it to collect data in the background it is necessary to add this call

class _MyAppState extends State<MyApp> {
  ...
  final _c4wLocationSdkFlutterPlugin = C4wLocationSdkFlutter();
  ...
  @override
  void initState() {
    super.initState();
    ...
    _c4wLocationSdkFlutterPlugin.sharedInstance();
    ...
  }

Usage Example

In this example we start tracking and save the LocationId

Remember: the SDK needs to have localization permissions to work. You need to implement methods to request these permissions from the user if your application doesn't have them.

Future<void> enableLocationTracking()  async {
  setState(() {
    _statusId = 'start tracking';
  });
  _c4wLocationSdkFlutterPlugin.enableLocationPermissionConsents();
  _c4wLocationSdkFlutterPlugin.startLocationTracking();
  try {
    String? id =
    await _c4wLocationSdkFlutterPlugin.getLocationId();
    setState(() {
      _statusId = "id: $id";
    });
  } catch (error) {
    setState(() {
      _statusId = "Error registration: $error";
    });
  }
}

Last updated

Was this helpful?