> 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/examples/ai-qa/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

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

Future<void> main() async {
  const userId = 'user-123';

  final notifier = DNotifier(
    appId: const String.fromEnvironment('DNOTIFIER_APP_ID'),
    secret: const String.fromEnvironment('DNOTIFIER_SECRET'),
    transport: 'http',
    userId: userId,
    logs: true,
  );

  await notifier.connect();

  final limits = notifier.getPlanLimits();
  if (limits?.aiEnabled != true) {
    throw StateError('AI is not enabled on this plan');
  }

  final response = await notifier.sendAI(
    senderId: userId,
    message: {'text': 'What are three benefits of realtime messaging?'},
  );

  print('AI response: $response');

  // Continue session if session id is available
  final sessionId = response is Map
      ? (response['metadata']?['packet']?['id'] ?? response['id'])?.toString()
      : null;

  if (sessionId != null) {
    final followUp = await notifier.sendAI(
      senderId: userId,
      sessionId: sessionId,
      message: {'text': 'Give me one concrete example for each.'},
    );
    print('Follow-up: $followUp');
  }

  final history = await notifier.fetchAIHistory(senderId: userId);
  print('History: $history');
}
```

## Run

```bash
dart run bin/ai_qa.dart \
  --define=DNOTIFIER_APP_ID=... \
  --define=DNOTIFIER_SECRET=...
```

## Flutter integration

Call `sendAI` from a button handler and display `response['data']['content']` (shape may vary by plan) in a `Text` widget. Show a loading indicator while awaiting the `Future`.
