> For the complete documentation index, see [llms.txt](https://docs.tryterra.co/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.tryterra.co/streaming-api/your-app-greater-than-terra/flutter.md).

# Flutter

Once you've started receiving data from a [device](/reference/streaming-api/core-concepts.md#device) into your app, you can start sending this data to Terra's websocket server.

{% hint style="info" %}

#### Prerequisite

Before following the steps below, make sure you've followed the guide to [stream data from a wearable device to your app](/streaming-api/connect-wearable-to-sdk/flutter.md)
{% endhint %}

## Streaming to Terra's Server

You'll have previously set up a local stream using `startRealtimeToApp`. To send data to Terra's server instead, use `startRealtimeToServer` with a **streaming token**:

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

Future<void> startServerStreaming() async {
  // 1. Get the Terra user ID
  final userId = await TerraFlutterRt.getUserId();
  if (userId == null) return;

  // 2. Get a streaming token from your backend
  final token = await fetchStreamingTokenFromBackend(userId);

  // 3. Start streaming to Terra's server
  await TerraFlutterRt.startRealtimeToServer(
    Connection.ble,
    [DataType.heartRate, DataType.steps],
    token,
  );
}
```

{% hint style="info" %}
**Flutter has separate functions** for local vs 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](/streaming-api/terra-greater-than-your-backend.md).
{% endhint %}

Your backend should generate the streaming token by calling:

{% openapi src="<https://raw.githubusercontent.com/tryterra/openapi/refs/heads/master/dist/rt-bundled.yaml>" path="/auth/user" method="post" %}
<https://raw.githubusercontent.com/tryterra/openapi/refs/heads/master/dist/rt-bundled.yaml>
{% endopenapi %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.tryterra.co/streaming-api/your-app-greater-than-terra/flutter.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
