> ## Documentation Index
> Fetch the complete documentation index at: https://docs.spikeapi.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Flutter SDK Setup

> This document provides a setup guide of the Spike SDK for Flutter platform.

## Version

**Current Flutter SDK Version:** `4.7.14`

## Resources

* Flutter Package: [Available here](https://pub.dev/packages/spike_flutter_sdk)
* Example app: [Available here](https://gitlab.com/spike_api/public/spike-sdk-examples/-/tree/master/flutter-v3/flutter_spike_v3)

## Requirements

* **iOS Version**: `13.0+`
* **Xcode 26+** is required.
* **Android Version**: `9.0+` (Level 28, P, Pie)

## Installation

Add a dependency on Spike SDK in your pubspec.yaml file:

```yaml theme={null}
dependencies:
  spike_flutter_sdk: ^4.3.34
```

## iOS Setup Guide

Use `pod install` and `pod update` commands from `ios/` folder of your app to install/update `SpikeSDK`.

### iOS Signing & Capabilities

To add HealthKit support to your application's Capabilities.

* Open the `ios/` folder of your project in Xcode
* Select the project name in the left sidebar
* Open the Signing & Capabilities section
* In the main view select '+ Capability' and double-click HealthKit

More details you can find [here](https://developer.apple.com/documentation/healthkit/setting_up_healthkit).

### Info.plist

Add Health Kit permissions descriptions to your `Info.plist` file:

```xml theme={null}
<key>NSHealthShareUsageDescription</key>
<string>We will use your health information to better track workouts.</string>

<key>NSHealthUpdateUsageDescription</key>
<string>We will update your health information to better track workouts.</string>
```

## Android Setup Guide

To add the SDK to your Android project, you have to add the following to your project's `build.gradle` file in the repositories block.

```gradle theme={null}
allprojects {
    repositories {
        // Other repositories
        maven {
            url 'https://gitlab.com/api/v4/projects/43396247/packages/maven'
        }
    }
}
```

Set Android SDK version in `local.properties` file:

```text theme={null}
flutter.minSdkVersion=28
flutter.compileSdkVersion=34
```

### Android Permissions

Include the necessary health permissions in your `AndroidManifest.xml` to fully leverage the Spike SDK and access data from apps integrated with Health Connect. Please refer to [this guide](https://developer.android.com/health-and-fitness/guides/health-connect/get-started#declare-permissions) for details on the required permissions.

**Note**: Only request permissions essential to your app’s functionality. Requesting unused permissions will lead to app store rejection!

```xml theme={null}
    <uses-permission android:name="android.permission.health.READ_NUTRITION"/>
    <uses-permission android:name="android.permission.health.READ_ACTIVE_CALORIES_BURNED"/>
    <uses-permission android:name="android.permission.health.READ_TOTAL_CALORIES_BURNED"/>
    <uses-permission android:name="android.permission.health.READ_STEPS"/>
    <uses-permission android:name="android.permission.health.READ_DISTANCE"/>
    <uses-permission android:name="android.permission.health.READ_ELEVATION_GAINED"/>
    <uses-permission android:name="android.permission.health.READ_RESTING_HEART_RATE"/>
    <uses-permission android:name="android.permission.health.READ_HEART_RATE_VARIABILITY"/>
    <uses-permission android:name="android.permission.health.READ_FLOORS_CLIMBED"/>
    <uses-permission android:name="android.permission.health.READ_BASAL_METABOLIC_RATE"/>
    <uses-permission android:name="android.permission.health.READ_SLEEP"/>
    <uses-permission android:name="android.permission.health.READ_HEART_RATE"/>
    <uses-permission android:name="android.permission.health.READ_EXERCISE"/>
    <uses-permission android:name="android.permission.health.READ_SPEED"/>
    <uses-permission android:name="android.permission.health.READ_POWER"/>
    <uses-permission android:name="android.permission.health.READ_OXYGEN_SATURATION"/>
    <uses-permission android:name="android.permission.health.READ_BLOOD_GLUCOSE"/>
    <uses-permission android:name="android.permission.health.READ_RESPIRATORY_RATE"/>
    <uses-permission android:name="android.permission.health.READ_WEIGHT"/>
    <uses-permission android:name="android.permission.health.READ_HEIGHT"/>
    <uses-permission android:name="android.permission.health.READ_BODY_FAT"/>
    <uses-permission android:name="android.permission.health.READ_LEAN_BODY_MASS"/>
    <uses-permission android:name="android.permission.health.READ_BODY_WATER_MASS"/>
    <uses-permission android:name="android.permission.health.READ_BODY_TEMPERATURE"/>
    <uses-permission android:name="android.permission.health.READ_BLOOD_PRESSURE"/>
    <uses-permission android:name="android.permission.health.READ_BONE_MASS"/>

```

Add an intent filter to your activity definition so that you can request the permissions at runtime.

```xml theme={null}
<intent-filter>
    <action android:name="androidx.health.ACTION_SHOW_PERMISSIONS_RATIONALE" />
</intent-filter>
```

Check the contents of `android/app/src/main/kotlin/{YOUR_PACKAGE_ID}/MainActivity.kt`. You must see something like that in case it is the new app being developed:

```kotlin theme={null}
import io.flutter.embedding.android.FlutterActivity

class MainActivity: FlutterActivity() {
}
```

You must change `FlutterActivity` to the `FlutterFragmentActivity` which means that your code should turn into the result similar to the one below:

```kotlin theme={null}
import io.flutter.embedding.android.FlutterFragmentActivity

class MainActivity: FlutterFragmentActivity() {
}
```

In the Health Connect permissions activity, there is a link to your privacy policy. You need to grant the Health Connect app access to link back to your privacy policy. In the example below, you should either replace .MainActivity with an activity that presents the privacy policy or have the Main Activity route the user to the policy. This step may be required to pass Google app review when requesting access to sensitive permissions.

```xml theme={null}
<activity-alias
     android:name="ViewPermissionUsageActivity"
     android:exported="true"
     android:targetActivity=".MainActivity"
     android:permission="android.permission.START_VIEW_PERMISSION_USAGE">
     <intent-filter>
         <action android:name="android.intent.action.VIEW_PERMISSION_USAGE" />
         <category android:name="android.intent.category.HEALTH_PERMISSIONS" />
     </intent-filter>
</activity-alias>
```

**Note**: If permissions handling is not working, this might be related to launch mode being singleTop. This might be not needed, but some apps face problems when requesting permissions.
If you face them, then you should try removing the property `android:launchMode="singleTop"`.

**Note**: If the app is not building, it might be related to the label replacement issue. In this case, you should add `tools:replace="android:label"` to the application tag:

```xml theme={null}
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
>

<application
    tools:replace="android:label"

```
