> For the complete documentation index, see [llms.txt](https://dnotifier.gitbook.io/product-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://dnotifier.gitbook.io/product-docs/reference/realtime-methods/dart-flutter.md). Agents can also search and read this documentation through its [MCP server](https://dnotifier.gitbook.io/product-docs/~gitbook/mcp).

# Dart / Flutter

Requires `transport: 'ws'` for push delivery to `onMessage`.

## `send()`

```dart
Future<dynamic> send({
  required String senderId,
  String? receiverId,
  List<String>? receiverIds,
  required dynamic data,
  bool saveHistory = true,
})
```

| Parameter     | Type            | Required | Default | Description             |
| ------------- | --------------- | -------- | ------- | ----------------------- |
| `senderId`    | `String`        | ✅        | —       | Sender user id          |
| `receiverId`  | `String?`       | \*       | —       | Single recipient        |
| `receiverIds` | `List<String>?` | \*       | —       | Multiple recipients     |
| `data`        | `dynamic`       | ✅        | —       | JSON-encodable payload  |
| `saveHistory` | `bool`          | —        | `true`  | Persist to chat history |

**Server metadata:** `type: 'text'`, `code: 200`

**Returns:** `Future<dynamic>` — RPC response over HTTP; nothing meaningful over WS for single-chunk sends.

**Chunking:** Large payloads are split when length exceeds `messageSizeLimit`.

### Example — text

```dart
await notifier.send(
  senderId: 'user-alice',
  receiverId: 'user-bob',
  data: {'type': 'text', 'text': 'Hello!'},
);
```

### Example — multiple receivers

```dart
await notifier.send(
  senderId: 'user-alice',
  receiverIds: ['user-bob', 'user-carol'],
  data: {'type': 'text', 'text': 'Hello everyone'},
);
```

## `sendBinary()`

```dart
void sendBinary({
  required String senderId,
  required List<String> receiverIds,
  required List<int> buffer,
  String type = 'binary',
})
```

| Parameter     | Type           | Required | Default    | Description    |
| ------------- | -------------- | -------- | ---------- | -------------- |
| `senderId`    | `String`       | ✅        | —          | Sender user id |
| `receiverIds` | `List<String>` | ✅        | —          | Recipients     |
| `buffer`      | `List<int>`    | ✅        | —          | Raw bytes      |
| `type`        | `String`       | —        | `'binary'` | Metadata type  |

**Server metadata:** `code: 202`

**Transport:** WebSocket only.

```dart
notifier.sendBinary(
  senderId: 'user-alice',
  receiverIds: ['user-bob'],
  buffer: [0x00, 0x01, 0x02],
);
```

## Receiving messages

```dart
onMessage: (DNotifierMessage msg) {
  final body = msg.payload.toJSON();
  // msg.metadata.id, .sender, .timestamp, .type
},
```

## Errors

| Error                                                     | Cause                               |
| --------------------------------------------------------- | ----------------------------------- |
| `StateError('Not connected')`                             | Not connected                       |
| `ArgumentError('senderId required')`                      | Missing sender                      |
| `ArgumentError('receiverId or receiverIds required')`     | No recipient                        |
| `UnsupportedError('Binary send not supported over HTTP')` | `send()` chunking edge case on HTTP |
