> 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/realtime-communication/structured-payloads/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

Send images, audio, and documents via `send()` with typed `data` objects.

***

## Image

```dart
import 'dart:io';
import 'package:dnotifier/dnotifier.dart';

Future<void> sendImage(DNotifier notifier) async {
  final imageBytes = await File('path/to/photo.png').readAsBytes();

  await notifier.send(
    senderId: 'user-alice',
    receiverId: 'user-bob',
    data: {
      'type': 'image',
      'content': imageBytes,
    },
  );
}
```

### Flutter image picker

```dart
import 'package:image_picker/image_picker.dart';

Future<void> sendPickedImage(DNotifier notifier, XFile file) async {
  final bytes = await file.readAsBytes();

  await notifier.send(
    senderId: myUserId,
    receiverId: peerUserId,
    data: {
      'type': 'image',
      'content': bytes,
      'fileName': file.name,
      'mimeType': 'image/jpeg',
    },
  );
}
```

***

## Audio

```dart
import 'dart:io';

Future<void> sendAudio(DNotifier notifier) async {
  final audioBytes = await File('path/to/voice-note.m4a').readAsBytes();

  await notifier.send(
    senderId: 'user-alice',
    receiverId: 'user-bob',
    data: {
      'type': 'audio',
      'content': audioBytes,
      'durationMs': 12500,
      'mimeType': 'audio/mp4',
    },
  );
}
```

***

## Document

```dart
import 'dart:io';

Future<void> sendDocument(DNotifier notifier) async {
  final docBytes = await File('path/to/report.pdf').readAsBytes();

  await notifier.send(
    senderId: 'user-alice',
    receiverId: 'user-bob',
    data: {
      'type': 'doc',
      'content': docBytes,
      'fileName': 'report.pdf',
      'mimeType': 'application/pdf',
    },
  );
}
```

***

## Receiving structured payloads

```dart
onMessage: (msg) {
  final body = msg.payload.toJSON();
  if (body is! Map) return;

  switch (body['type']) {
    case 'image':
      final bytes = body['content'];
      if (bytes is List<int>) {
        showImagePreview(bytes);
      }
      break;
    case 'audio':
      playAudio(body['content'], body['mimeType'] as String?);
      break;
    case 'doc':
      saveAndOpenFile(
        body['content'],
        body['fileName'] as String?,
        body['mimeType'] as String?,
      );
      break;
  }
},
```

***

## Size limits

```dart
await notifier.connect();
print('Max chunk size: ${notifier.messageSizeLimit}');
```

Payloads larger than `messageSizeLimit` are chunked automatically.

→ [Large messages & chunking](https://dnotifier.gitbook.io/product-docs/realtime-communication/chunking.md)

***

## Learn more

* [Binary messaging](https://dnotifier.gitbook.io/product-docs/realtime-communication/binary-messaging/dart-flutter.md)
* [Chat UI patterns](https://dnotifier.gitbook.io/product-docs/chat/ui-patterns.md)
