RT Streaming - Flutter

Using the package

The Terra Real Time package offers the capability to stream data either in your app directly using a callback function, or to your server using websockets.

Import the package in your app file:

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

The first line is for all the functionality. The types are for the different data types (connections, requested data types, and received data type). The iOS controller is for the iOS scanning controller UI.

Everytime your app opens, you need to initialise the library:

await TerraFlutterRt.init(devId, "reference_id");

The first time ever you want to use the package, you need to register the device with Terra using initConnection. You can generate an SDK token from here using your Terra dev credentatials:

await TerraFlutterRt.initConnection(sdktoken);

and then get the user id using getUserId

const userId = await TerraFlutterRt.getUserId();

The packages support streaming from the following wearable types:

enum Connection { ble, apple, wearOs, android, ant }

and supports streaming the following data types:

enum DataType {

An example using a connection and a set of data to be streamed:

const connection = Connection.ble;
const datatypes = [DataType.heartRate];

For BLE connections and ANT+, you can pull a scanning UI for the user to select a device:

if (connection == Connection.ble ||
        connection == Connection.wearOs ||
        connection == Connection.ant ||
        connection == Connection.allDevices) {
      await TerraFlutterRt.startDeviceScan(connection);

you can optionally cache the devices. If set to true, this options will not pull the scan screen if one of the cached devices is found:

await TerraFlutterRt.startDeviceScan(connection, useCache: true);
With the device and dataypes set, you can now start streaming. To stream locally in your app directly, you can pass a callback function that will get triggered with the data:

void dataCallback(Update data) {
  print("Got data in app");

// .......

await TerraFlutterRt.startRealtimeToApp(connection, datatypes, dataCallback);

Example payloads:



To stream to your server using Websockets, you need a websocket token generated from here:

await TerraFlutterRt.startRealtimeToServer(connection, datatypes, websockettoken);

Example payloads:



Finally, you can stop streaming and disconnect the device on command:

await TerraFlutterRt.stopRealtime(connection);
await TerraFlutterRt.disconnect(connection);