Flutter

Flutter Functions

Connection Setup

init

Initializes a connection with the Terra backend for the device.

dartCopy codestatic Future<bool?> init(String devId, String? referenceId) async
  • devId: The developer ID used for initialization.

  • referenceId: An optional reference ID.

  • Returns: A Future<bool?> indicating if the initialization was successful or not.

initConnection

Initializes a user session with Terra backend using an authentication token.

dartCopy codestatic Future<bool?> initConnection(String token) async
  • token: The authentication token generated by the backend.

  • Returns: A Future<bool?> indicating if the session was successfully initialized.

getUserId

Retrieves the user ID for the current device.

dartCopy codestatic Future<String?> getUserId() async
  • Returns: A Future<String?> representing the user's Terra ID, or null if no ID is found.

disconnect

Disconnects the device from a given connection.

dartCopy codestatic Future<bool?> disconnect(Connection connection) async
  • connection: The connection object specifying which connection to disconnect.

  • Returns: A Future<bool?> indicating if the disconnection was successful.


Device Scanning

startDeviceScan

Starts a device scan and allows connection to devices.

dartCopy codestatic Future<bool?> startDeviceScan(Connection connection, {bool useCache = false}) async
  • connection: The connection object specifying the type of connection to initiate.

  • useCache: A boolean flag to indicate if cached devices should be used (default: false).

  • Returns: A Future<bool?> indicating if the device scan was successful.


Data Streaming

startRealtimeToServer

Starts real-time data streaming from the device to the server.

dartCopy codestatic Future<bool?> startRealtimeToServer(Connection connection, List<DataType> types, String token) async
  • connection: The connection object specifying which connection to stream from.

  • types: A list of DataType objects indicating which types of data to stream.

  • token: An authentication token for the streaming session.

  • Returns: A Future<bool?> indicating if the real-time streaming was successfully started.

startRealtimeToApp

Starts real-time data streaming from the device to the app.

dartCopy codestatic Future<bool?> startRealtimeToApp(Connection connection, List<DataType> types, UpdateCallback callback) async
  • connection: The connection object specifying which connection to stream from.

  • types: A list of DataType objects indicating which types of data to stream.

  • callback: A function (UpdateCallback) that is called whenever new data is available.

  • Returns: A Future<bool?> indicating if the real-time streaming was successfully started.

stopRealtime

Stops real-time data streaming for a given connection.

dartCopy codestatic Future<bool?> stopRealtime(Connection connection) async
  • connection: The connection object specifying which connection to stop streaming from.

  • Returns: A Future<bool?> indicating if the streaming was successfully stopped.


Utility

platformVersion

Retrieves the platform version for the current device.

dartCopy codestatic Future<String?> get platformVersion async
  • Returns: A Future<String?> containing the platform version, or "UNKNOWN" if not available.

Types

Connection Enum

The Connection enum represents the different connection types available in the Terra Flutter SDK.

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

Each connection type can be converted to a string using the connectionString property, which maps the enum values to their respective string representations (e.g., Connection.ble becomes "BLE").

DataType Enum

The DataType enum represents the different types of data that can be streamed from a device.

enum DataType {
  heartRate,
  ecg,
  steps,
  hrv,
  calories,
  location,
  speed,
  distance,
  stepsCadence,
  floorsClimbed,
  gyroscope,
  acceleration
}

Each DataType can be converted to a string using the datatypeString property, which maps the enum values to their respective string representations (e.g., DataType.heartRate becomes "HEART_RATE").

Update Class

The Update class represents a data update received from the device.

class Update {
  final String ts;           // Timestamp of the update
  final DataType type;       // Type of data (e.g., heart rate, steps)
  final double? val;         // Single value for the data type (if applicable)
  final List<double>? d;     // List of values for complex data types (e.g., acceleration)
}

You can create an Update object from a JSON map using the Update.fromJson constructor.

Was this helpful?