Flutter
Flutter Functions
Connection Setup
init
Initializes a connection with the Terra backend for the device.
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.
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.
Returns: A
Future<String?>
representing the user's Terra ID, ornull
if no ID is found.
disconnect
Disconnects the device from a given connection.
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.
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.
connection
: The connection object specifying which connection to stream from.types
: A list ofDataType
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.
connection
: The connection object specifying which connection to stream from.types
: A list ofDataType
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.
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.
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.
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.
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.
You can create an Update
object from a JSON map using the Update.fromJson
constructor.
Was this helpful?