Skip to main content

Installation

Add the following dependencies to your pubspec.yaml file:
$ flutter pub add dartantic_chat

Configuration

Get your API key from the Google AI Studio or your preferred LLM provider. Run your app with the API key:
flutter run --dart-define=GEMINI_API_KEY=your-api-key-here
In your Dart code, initialize the agent:
import 'package:dartantic_ai/dartantic_ai.dart';
import 'package:dartantic_chat/dartantic_chat.dart';

const _apiKey = String.fromEnvironment('GEMINI_API_KEY');

void main() {
  assert(_apiKey.isNotEmpty, 'GEMINI_API_KEY not provided via --dart-define');
  Agent.environment['GEMINI_API_KEY'] = _apiKey;
  runApp(const App());
}
Then create your chat interface:
class ChatPage extends StatelessWidget {
  const ChatPage({super.key});

  @override
  Widget build(BuildContext context) => Scaffold(
    appBar: AppBar(title: const Text('Chat')),
    body: AgentChatView(
      provider: DartanticProvider(
        agent: Agent('gemini'),
      ),
    ),
  );
}
For a complete usage example, check out the gemini.dart sample.

Using Other LLM Providers

dartantic_ai supports multiple providers. Set the appropriate API key and configure the Agent:
// OpenAI
Agent.environment['OPENAI_API_KEY'] = openaiKey;
final agent = Agent('openai-responses:gpt-4o');

// Anthropic
Agent.environment['ANTHROPIC_API_KEY'] = anthropicKey;
final agent = Agent('anthropic:claude-3-5-sonnet');

// Ollama (local, no API key needed)
final agent = Agent('ollama:llama3.2');

Device Permissions

To enable your users to take advantage of features like voice input and media attachments, ensure that your app has the necessary permissions:

Network Access

On macOS, add the following to your *.entitlements files:
<plist version="1.0">
    <dict>
      ...
      <key>com.apple.security.network.client</key>
      <true/>
    </dict>
</plist>
On Android, ensure your AndroidManifest.xml contains:
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
    ...
    <uses-permission android:name="android.permission.INTERNET"/>
</manifest>

Clipboard Access

To enable copying and pasting images and other custom data to and from the Android clipboard, add the following content provider to your AndroidManifest.xml inside the <application> tag:
<manifest>
    <application>
        ...
        <provider
            android:name="com.superlist.super_native_extensions.DataProvider"
            android:authorities="<your-package-name>.SuperClipboardDataProvider"
            android:exported="true"
            android:grantUriPermissions="true">
        </provider>
        ...
    </application>
</manifest>
Be sure to replace <your-package-name> with your actual package name (e.g., com.example.myapp).

Other Permissions

Running Examples

Provide your API key via --dart-define:
cd packages/dartantic_chat/example
flutter run --dart-define=GEMINI_API_KEY=your-api-key-here
See the example apps.