> For the complete documentation index, see [llms.txt](https://create.cloud4wi.ai/dev-hub/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://create.cloud4wi.ai/dev-hub/location-sdk/integrating-the-sdk/flutter/quickstart.md).

# 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:

```shell
 $ 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:

```dart
import 'package:c4w_location_sdk_flutter/c4w_location_sdk_flutter.dart';
```

## Android installation

### Integration&#x20;

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

**Replace x.y.z with a specific version of library that you can find** [**here**](https://create.cloud4wi.com/dev-hub/location-sdk/integrating-the-sdk/android/changelog)

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

dependencies {
    ...

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

### Configuration <a href="#configuration" id="configuration"></a>

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)

```gradle
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.

```gradle
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 <a href="#required-permissions" id="required-permissions"></a>

`AndroidManifest` of this library requires following permissions

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

\
iOS installation <a href="#usage-example" id="usage-example"></a>
-----------------------------------------------------------------

### Configuration <a href="#configuration" id="configuration"></a>

**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)

```xml
<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

```xml
<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 <a href="#usage-example" id="usage-example"></a>

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

```dart
class _MyAppState extends State<MyApp> {
  ...
  final _c4wLocationSdkFlutterPlugin = C4wLocationSdkFlutter();
  ...

```

```dart
  @override
  void initState() {
    super.initState();
    ...
    _c4wLocationSdkFlutterPlugin.sharedInstance();
    ...
  }
```

## Usage Example <a href="#usage-example" id="usage-example"></a>

In this example we start tracking and save the LocationId

<mark style="color:red;">**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.**</mark>

```dart
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";
    });
  }
}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://create.cloud4wi.ai/dev-hub/location-sdk/integrating-the-sdk/flutter/quickstart.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
