|
| 1 | +--- |
| 2 | +title: Perplexity Dart & Flutter SDKs |
| 3 | +description: Lightweight, type-safe SDKs for seamless Perplexity API integration in Dart and Flutter applications |
| 4 | +sidebar_position: 3 |
| 5 | +keywords: [Perplexity, Flutter, Dart, SDK, API, streaming, chat-completions, sonar, type-safe, widgets] |
| 6 | +--- |
| 7 | + |
| 8 | +# Perplexity Dart & Flutter SDKs |
| 9 | + |
| 10 | +**Perplexity Dart & Flutter SDKs** provide comprehensive toolkit for integrating Perplexity's AI capabilities into Dart and Flutter applications. Built specifically for the Flutter community, these packages include a lightweight core API client and ready-to-use Flutter widgets with BLoC state management. |
| 11 | + |
| 12 | +## Features |
| 13 | + |
| 14 | +* Type-safe API client with fully typed models and compile-time safety |
| 15 | +* Streaming and non-streaming chat completions with real-time response handling |
| 16 | +* Support for all Perplexity models (Sonar, Sonar Pro, Deep Research, Reasoning variants) |
| 17 | +* Multi-image processing with base64, data URI, and HTTPS URL support |
| 18 | +* Ready-to-use Flutter widgets with BLoC state management integration |
| 19 | +* Advanced configuration options (temperature, top-p, search filters, domain restrictions) |
| 20 | +* Cross-platform support for iOS, Android, Web, and Desktop |
| 21 | +* Future-proof design with custom model string support for new Perplexity releases |
| 22 | + |
| 23 | +## Prerequisites |
| 24 | + |
| 25 | +* Dart SDK 2.17.0 or newer |
| 26 | +* Flutter SDK 3.0.0 or newer (for Flutter-specific features) |
| 27 | +* Perplexity API key from Perplexity API Console |
| 28 | +* Basic knowledge of Flutter BLoC pattern for widget integration |
| 29 | + |
| 30 | +## Installation |
| 31 | + |
| 32 | +### For Dart Projects (Core API Only) |
| 33 | + |
| 34 | +```bash |
| 35 | +dart pub add perplexity_dart |
| 36 | +``` |
| 37 | + |
| 38 | +### For Flutter Projects (Full Widget Support) |
| 39 | + |
| 40 | +```bash |
| 41 | +flutter pub add perplexity_flutter |
| 42 | +``` |
| 43 | + |
| 44 | +### Environment variables |
| 45 | + |
| 46 | +```dart |
| 47 | +// Add to your app's configuration |
| 48 | +const String perplexityApiKey = 'your_perplexity_api_key_here'; |
| 49 | +``` |
| 50 | + |
| 51 | +## Usage |
| 52 | + |
| 53 | +**Core API Integration:** |
| 54 | +- Type-safe client with all Perplexity models (Sonar, Sonar Pro, Deep Research, Reasoning) |
| 55 | +- Streaming and non-streaming chat completions |
| 56 | +- Multimodal processing with flexible MessagePart system for text + images |
| 57 | + |
| 58 | +**Flutter Widget Layer:** |
| 59 | +- `ChatWrapperWidget` for BLoC state management |
| 60 | +- `PerplexityChatView` for real-time message display |
| 61 | +- `PerplexityChatInput` for user interaction handling |
| 62 | + |
| 63 | +## Code Explanation |
| 64 | + |
| 65 | +* Core Layer: Pure Dart API client (`perplexity_dart`) for cross-platform Perplexity API integration |
| 66 | +* UI Layer: Flutter widgets (`perplexity_flutter`) with BLoC state management for rapid development |
| 67 | +* Type Safety: Fully typed models and responses prevent runtime errors and provide IntelliSense |
| 68 | +* Multimodal: Flexible MessagePart system for combining text and images in single requests |
| 69 | +* Streaming: Built-in support for real-time chat completions with proper chunk handling |
| 70 | +* Architecture: Two-layer design allows lightweight API usage or full Flutter widget integration |
| 71 | + |
| 72 | +## Architecture |
| 73 | + |
| 74 | +**Two-layer design:** |
| 75 | +- **Core (`perplexity_dart`)** - Pure Dart API client for all platforms |
| 76 | +- **UI (`perplexity_flutter`)** - Flutter widgets + BLoC state management |
| 77 | + |
| 78 | +Uses flexible MessagePart system for multimodal content combining text and images. |
| 79 | +## Links |
| 80 | + |
| 81 | +**Packages:** |
| 82 | +- [perplexity_dart on pub.dev](https://pub.dev/packages/perplexity_dart) | [GitHub](https://github.com/vishnu32510/perplexity_dart) |
| 83 | +- [perplexity_flutter on pub.dev](https://pub.dev/packages/perplexity_flutter) | [GitHub](https://github.com/vishnu32510/perplexity_flutter) |
| 84 | + |
| 85 | +**Examples:** |
| 86 | +- [Flutter Example App](https://github.com/vishnu32510/perplexity_dart/tree/main/example_flutter_app) |
| 87 | +- [Dart Examples](https://github.com/vishnu32510/perplexity_dart/tree/main/example) |
| 88 | + |
| 89 | +**Contributing:** Issues and PRs welcome on both repositories. |
0 commit comments