spike_flutter_sdk 1.0.7 copy "spike_flutter_sdk: ^1.0.7" to clipboard
spike_flutter_sdk: ^1.0.7 copied to clipboard

Reads HealthKit data from iOS HealthKit, and syncs it with Spike backend.

Spike Flutter SDK allows you to read the Apple HealthKit and Android Health Connect data. Then, it allows you to send the data to your backend chosen, and get the data returned which is processed by the backend. Also, you can enable background delivery in case iOS device is being used. And finally, it is possible to enable event tracking to see if everything works as intended or just provide your own event tracking library.

Features #

  1. Read the Apple HealthKit data.
  2. Send this data to backend.
  3. Register periodic background tasks to send and read the data.
  4. Track various events of the package by utilizing shared preferences.

Getting started #

Setup everything like you would to with https://pub.dev/packages/health_kit_reporter . Then, use this library as shown in example below (or in the longer one).

Usage #

The examples below demonstrates how to use this package in various of cases.

Initialization #

First, you must get the correct credentials in order for this package to be usable.

const authToken = 'fa0b3803-6068-4ea7-9788-eccce210d30c';
const appId = 'ea9e03f5-be45-49fb-bf4c-47a88c184c3b';
const customerEndUserId = 'jasbdhasbfashfj';
const postbackURL = 'https://example.com/';
const host = 'https://api.spikeapi.com';
copied to clipboard

Creating connection #

Using the credentials received, you can create the connection. It is super trivial and just too easy to do.

final connection = await SpikeSDK.createConnection(
  host: host,
  appId: appId,
  authToken: authToken,
  customerEndUserId: customerEndUserId,
);
copied to clipboard

Creating WebHook connection #

Creating Web Hook connection is also super easy to create.

final webHookConnection = await SpikeSDK.createConnection(
  host: host,
  appId: appId,
  authToken: authToken,
  customerEndUserId: customerEndUserId,
  postbackURL: postbackURL,
);
copied to clipboard

Requesting permissions #

In order to use the connection properly, you must first ask for the permissions needed for your purposes. Let us assume you want to get heart data. For this, you must to ask for heart data permissions. See the example below about how easy it is to do so.

SpikeSDK.ensurePermissionsAreGranted([SpikeDataType.heart]);
copied to clipboard

Just one line of code, and you are requesting the permissions.

Using the connection #

Using both simple and Web Hook connections are very easy to use. See the example below.

final heartData = await connection.extractData(SpikeDataType.heart);
final heartJobDetails = await webHookConnection.extractAndPostData(SpikeDataType.heart);
copied to clipboard

Enabling background delivery (WebHook connection and iOS only) #

Enabling the background delivery should be straightforward as shown below.

await SpikeSDK.enableBackgroundDelivery(
  connection: webHookConnection,
  types: [SpikeDataType.summary, SpikeDataType.heart],
  intervalSeconds: 30, // 0 would be for immediate delivery of the data.
);
copied to clipboard

After the background delivery is enabled, its' all relevant data is stored in memory, and you do not need to enable it again when the app opens again.

Disabling background delivery (WebHook connection and iOS only) #

Disabling the background delivery is even more simplier.

await SpikeSDK.disableBackgroundDelivery(
  connection: webHookConnection,
);
copied to clipboard

Checking the background delivery types (WebHook connection and iOS only) #

Sometimes you may want to check for which types the connection is registered for the background delivery. This is very simple.

final types = await SpikeSDK.getBackgroundDeliveryTypes(
  connection: webHookConnection,
);
copied to clipboard
5
likes
0
points
1.11k
downloads

Publisher

verified publisherspikeapi.com

Weekly Downloads

2024.10.07 - 2025.04.21

Reads HealthKit data from iOS HealthKit, and syncs it with Spike backend.

Homepage

License

unknown (license)

Dependencies

cryptography, flutter, get_it, hex, http, shared_preferences, update, uuid

More

Packages that depend on spike_flutter_sdk