We strongly recommend reading the documentation for both native iOS and Android. The Flutter SDK is a thin layer sitting on top of these SDKs.

Please check our sample app, that makes full use of the SDK.

1. Introduction

The Vital SDK is split into three main components: vital_core, vital_health and vital_devices.

  • vital_core holds common components to both vital_health and vital_devices. Among other things, it has the network layer that allows us to send data from a device to a server.
  • vital_health is an abstraction over HealthKit and Health Connect.
  • vital_devices is an abstraction over a set of Bluetooth devices.

2. Vital Core

Initialise client with region, environment and api key

final client = VitalClient()
  ..init(region: Region.eu, environment: Environment.sandbox, apiKey: 'sk_eu_...');

Query users:

final Response<List<User>> usersResponse = client.userService.getAll();

Link data provider:

client.linkProvider(user, 'strava','vitalexample: //callback');

3. Vital Health

We recommend reading both the Native iOS Guide and the Apple HealthKit Guide, since those docs apply to all platforms.

1. Getting Started

1. Setup ios

Please read the iOS SDK instructions on Apple HealthKit. You need to edit your Capababilities and the Info.plist file.

2. Setup android

Please read the Android SDK instructions on Health Connect. You need to edit your AndroidManifest.xml and add an xml with your requested health permssions.

3. Setup flutter

First create your client:

final HealthServices healthServices = HealthServices(
  apiKey: apiKey,
  region: region,
  environment: Environment.sandbox,
)

You can then configure it:

await healthServices.configureClient();

await healthServices.configureHealth(
      config: const HealthConfig(
        iosConfig: IosHealthConfig(
          backgroundDeliveryEnabled: true,
        ),
      ),
    );

And set the userId:

await client.healthServices.setUserId('eba7c0a2-dc01-49f5-a361-...);

2. Using the SDK

You need to ask for permissions before getting data. For example the following allows you to read and write water:

final List<HealthResource> readResources = [HealthResource.water];
final List<HealthResourceWrite> writeResources = [
    HealthResourceWrite.water,
  ];

client.healthServices.ask(readResources, writeResources);

And syncing data:

client.healthServices.syncData();

Syncing starts automatically without calling this method after the health client initialised and the user id is set.

You can also write data:

client.healthServices.writeHealthData(HealthResourceWrite.water, startDate, endDate, 1000);

Not all resources are writable in both iOS and Android. Please refer to the health_resource.dart file.

Finally, observe the status stream, so you can react to changes:

Stream<SyncStatus> status = client.healthServices.status;

3. Background Delivery

Setting up background syncing in Flutter follows the same approach as native iOS. You need to configure VitalHealthKit in the AppDelegate, otherwise background syncing won’t work.

You can do so by calling VitalHealthKitClient.configure inside application:didFinishLaunchingWithOptions:

import UIKit
import Flutter
import VitalHealthKit

@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
  override func application(
    _ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
  ) -> Bool {

      VitalHealthKitClient.configure(
      .init(
          mode: ..., // automatic by default
          backgroundDeliveryEnabled: ..., // false by default
          logsEnabled: ..., // false by default
          numberOfDaysToBackFill: ..., // 90 by default
      )
    )

    GeneratedPluginRegistrant.register(with: self)
    return super.application(application, didFinishLaunchingWithOptions: launchOptions)
  }
}

You can also check our Flutter example. In our example, we use the VitalHealthKitClient.automaticConfiguration() variant. This version assumes that VitalHealthKitClient.configure was called at some point in the past (e.g. when the user was logged in). For example,automaticConfiguration is helpful when you are doing A/B testing and you only want to enroll certain users with Apple HealthKit.

4. Vital Devices

1. Getting Started

1. iOS

Add the following to your Info.plist file:

<key>NSBluetoothAlwaysUsageDescription</key>
<string>Our app uses bluetooth to find, connect and transfer data between different devices</string>

You will have to request the bluetooth permission in your app before using the SDK.

2. Android

Add the following to your AndroidManifest.xml:

<uses-permission android:name="android.permission.BLUETOOTH_SCAN" android:usesPermissionFlags="neverForLocation"/>
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT"/>

        <!-- Request legacy Bluetooth permissions on older devices. -->
<uses-permission android:name="android.permission.BLUETOOTH" android:maxSdkVersion="30"/>
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" android:maxSdkVersion="30"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" android:maxSdkVersion="30"/>

You will have to request the appropriate permissions at in your app before you can call the Vital Devices SDK.

2. Usage

First you have to scan for one of the supported devices. You can find the list of supported devices by calling DeviceManager().devices.

 vitalDevices.scanForDevices(deviceModel).listen((device) {
    // now you have the device you were looking for
  });

Depending on the type of device you are connecting to, you will have to call different methods to connect to it.

1. Blood pressure monitor

  vitalDevices.readBloodPressureData(scannedDevice).listen((bloodPressureSamples) {
    // you will receive a list of blood pressure samples
  });

2. Glucose meter

  vitalDevices.readGlucoseMeterData(scannedDevice).listen((glucoseSamples) {
    // you will receive a list of glucose samples
  });

After you have received samples depending on the type of device you might need to star scanning again to receive the next set of samples.

5. Migrate from 0.3._ and 0.4._ to 0.5.*

Our original package vital_flutter is now separated into 3 packages: vital_core, vital_health and vital_devices.

  • vital_core contains the Vital Client
  • vital_health contains the Apple Health sync
  • vital_devices contains the sdk for bluetooth devices

vital_health and vital_devices are dependent vital_core.

To migrate you will need to add the new plugins you need in your pubspec.yaml file:

dependencies:
  flutter:
    sdk: flutter
  vital_core: ^latest_version
  vital_health: ^latest_version
  vital_devices: ^latest_version

All the imports have to be updated too. As an example: import 'package:vital_flutter/services/data/user.dart';

needs to be changes import 'package:vital_core/services/data/user.dart';

You can get all the classes by using:

import 'package:vital_core/vital_core.dart';
import 'package:vital_devices/vital_devices.dart';
import 'package:vital_health/vital_health.dart';

Your IDE should offer the correct import after you have updated your pubspec.yaml

Important changes

  • DeviceManager was moved out of the VitalClient to the vital_devices package
  • HealthkitServices is now in the vital_health package
  • VitalClient is now in vital_core package