For the complete documentation index, see llms.txt. This page is also available as Markdown.

Flutter SDK

Connect a BLE wearable or Apple Watch to your Flutter app with terra_flutter_rt, then stream its data to Terra.

Install the SDK

  1. Add terra_flutter_rt to your pubspec.yaml:

dependencies:
  terra_flutter_rt: ^X.X.X
  1. iOS: In your Info.plist, add:

    • Privacy - Bluetooth Always Usage Description: Justification for BLE usage

    • Privacy - Motion Usage Description: Justification for motion sensor usage (required if streaming accelerometer, gyroscope, or step data from the phone's built-in sensors via Connection.apple)

  2. Android: Permissions are requested automatically by the SDK on initialization.

Initialize the SDK

Initialize the SDK every time the app is opened or brought into the foreground.

import 'package:terra_flutter_rt/terra_flutter_rt.dart';
import 'package:terra_flutter_rt/types.dart';

await TerraFlutterRt.init('YOUR_DEV_ID', 'YOUR_REFERENCE_ID');

Register the phone

Register the phone with Terra using an authentication token generated from your backend:

To generate the token, make the below call from your backend:

Deprecated

Generate a mobile SDK auth token (deprecated)

post

Same as POST /auth/tokens, under the older path that shipped mobile SDK versions call.

  • Stays available indefinitely; new integrations should use POST /auth/tokens.
Authorizations
x-api-keystringRequired

Your API key for authentication

dev-idstringRequired

Your developer ID for authentication and tracking

Query parameters
reference_idstringOptional

Your identifier for the end user this token is being issued for. When supplied, the token is bound to it and redemption ignores the reference_id the SDK sends, so a token cannot be used to attach a device to a different user. Omit to keep the SDK-supplied value.

Example: user-42
Responses
200

200

application/json
statusstringOptionalExample: success
tokenstringOptionalExample: 250c68b9c21b78e40e7a3285a2d538d3bc24aabd3b4c76a782fb0a571ca4501d
expires_inintegerOptionalDefault: 0Example: 180
post/auth/generateAuthToken
POST /api/v2/auth/generateAuthToken HTTP/1.1
Host: access.tryterra.co
x-api-key: YOUR_API_KEY
dev-id: YOUR_API_KEY
Accept: */*
{
  "status": "success",
  "token": "250c68b9c21b78e40e7a3285a2d538d3bc24aabd3b4c76a782fb0a571ca4501d",
  "expires_in": 180
}

Scan for devices

Two approaches depending on your needs:

Use the built-in scan widget

On Android, this shows a native device picker. On iOS, use the iOSScanView widget.

Scan programmatically

Discover devices one by one and connect manually:

Start streaming

Once a device is connected, start streaming data to your app via a callback:

To stream to Terra's server instead, see Stream to Terra.

Stop streaming and disconnect

Stream from an Apple Watch

To stream data from an Apple Watch:

The watchOS app itself must be written in native Swift using the Terra class from the TerraRTiOS framework. See the iOS SDK page for the watch-side setup.

You can also control workout sessions on the watch from your Flutter app:

Stream to Terra

Once data from the wearable reaches your app, you can send it to Terra's websocket server. Your backend then receives it through a backend consumer.

The local stream uses startRealtimeToApp. To send data to Terra's server instead, use startRealtimeToServer with a streaming token:

Flutter has separate functions for local and server streaming:

  • startRealtimeToApp: streams to a local callback only (no server)

  • startRealtimeToServer: streams to Terra's websocket server only (no local callback)

To receive data both locally and on your server, call startRealtimeToApp for the local callback and have your backend consume from the Terra websocket.

Your backend should generate the streaming token by calling:

Stream - Generate user token

post

Returns a token that opens a producer connection for one user, to push that user's live samples.

  • By default the token is single-use and short-lived.
  • With reusable=true the same token opens a connection on every reconnect until it expires or is revoked with POST /auth/user/revoke, and the response adds expires_in.
Authorizations
x-api-keystringRequired

Your API key for authentication

dev-idstringRequired

Your developer ID for authentication and tracking

Query parameters
idstringRequired

The user the token is for: their Terra user ID (a UUID, returned when they connect), their connection_id, or a streaming test user's t_ ID from the dashboard's "generate test data" tool. A user who is not connected under your developer ID, or a test user that has expired, gets 403.

reusablebooleanOptional

Set to true for a reusable token instead of a single-use one. Defaults to false. A test user (t_ ID) cannot have a reusable token and gets 400.

Default: false
Responses
200

Token generated.

application/json
tokenstringRequired

Token to present in the IDENTIFY frame. A reusable token starts with rt..

Example: OTYwNWFi5ZWQMTAxMjg0Y2Qw.gzrPzZcS3Gy8QDOxbiPRwu30PTB3VxW0eE
expires_inintegerOptional

Seconds until the reusable token expires, never later than the credential that minted it. Present only with reusable=true.

Example: 28800
post/auth/user
POST /auth/user?id=text HTTP/1.1
Host: ws.tryterra.co
x-api-key: YOUR_API_KEY
dev-id: YOUR_API_KEY
Accept: */*
{
  "token": "OTYwNWFi5ZWQMTAxMjg0Y2Qw.gzrPzZcS3Gy8QDOxbiPRwu30PTB3VxW0eE",
  "expires_in": 28800
}

Last updated

Was this helpful?