@@ -7,190 +7,83 @@ keywords: [Perplexity, Flutter, Dart, SDK, API, streaming, chat-completions, son
77
88# Perplexity Dart & Flutter SDKs
99
10- Comprehensive toolkit for integrating Perplexity's AI capabilities into Dart and Flutter applications. Includes a lightweight core API client ( ` perplexity_dart ` ) and Flutter widgets ( ` perplexity_flutter ` ) with BLoC state management.
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.
1111
1212## Features
1313
14- - ** Type-safe API Client ** - Fully typed models with compile-time safety
15- - ** Streaming & Non -streaming** - Real-time chat completions with streaming support
16- - ** All Perplexity Models ** - Sonar, Sonar Pro, Deep Research, Reasoning variants
17- - ** Multi-Image Processing ** - Single or multiple images ( base64, data URI, HTTPS URLs)
18- - ** Flutter Widgets ** - Ready-to-use chat UI components with BLoC integration
19- - ** Advanced Configuration ** - Temperature , top-p, search filters, domain restrictions
20- - ** Cross-platform** - iOS, Android, Web, Desktop support
21- - ** Future-proof** - Custom model string support for new Perplexity releases
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
2222
2323## Prerequisites
2424
25- - Dart SDK 2.17.0+
26- - Flutter SDK 3.0.0+ (for Flutter features)
27- - [ Perplexity API Key] ( https://www.perplexity.ai/settings/api )
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
2829
2930## Installation
3031
32+ ### For Dart Projects (Core API Only)
33+
3134``` bash
32- # For Dart projects
3335dart pub add perplexity_dart
34-
35- # For Flutter projects
36- flutter pub add perplexity_flutter
3736```
3837
39- ## Usage
40-
41- ### Flutter Widgets (Quick Start)
38+ ### For Flutter Projects (Full Widget Support)
4239
43- ``` dart
44- import 'package:flutter/material.dart';
45- import 'package:perplexity_flutter/perplexity_flutter.dart';
46-
47- void main() => runApp(MaterialApp(
48- home: ChatWrapperWidget(
49- apiKey: 'your-api-key',
50- model: PerplexityModel.sonarPro,
51- child: Scaffold(
52- appBar: AppBar(title: Text('AI Chat')),
53- body: Column(children: [
54- Expanded(child: PerplexityChatView()),
55- PerplexityChatInput(),
56- ]),
57- ),
58- ),
59- ));
40+ ``` bash
41+ flutter pub add perplexity_flutter
6042```
6143
62- ### Core API Client
44+ ### Environment variables
6345
6446``` dart
65- import 'package:perplexity_dart/perplexity_dart.dart';
66-
67- final client = PerplexityClient(apiKey: 'your-api-key');
68-
69- // Simple chat
70- final response = await client.sendMessage(
71- requestModel: ChatRequestModel(
72- model: PerplexityModel.sonarPro,
73- messages: [
74- StandardMessageModel(role: MessageRole.user, content: 'Hello AI'),
75- ],
76- ),
77- );
78- print('Response: ${response.content}');
79-
80- // Streaming
81- final stream = client.streamChat(requestModel: ChatRequestModel(
82- model: PerplexityModel.sonar,
83- messages: messages,
84- stream: true,
85- ));
86-
87- await for (final chunk in stream) {
88- print('Chunk: $chunk');
89- }
47+ // Add to your app's configuration
48+ const String perplexityApiKey = 'your_perplexity_api_key_here';
9049```
9150
92- ### Image Analysis
93-
94- ``` dart
95- // Single image
96- final request = ChatRequestModel.defaultImageRequest(
97- urlList: ['https://example.com/image.jpg'],
98- imagePrompt: 'Describe this image',
99- model: PerplexityModel.sonarPro,
100- );
101-
102- // Multiple images
103- final multiRequest = ChatRequestModel.defaultImageRequest(
104- urlList: [
105- 'https://example.com/photo1.jpg',
106- 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgA...'
107- ],
108- imagePrompt: 'Compare these images',
109- );
110-
111- final response = await client.sendMessage(requestModel: request);
112- ```
51+ ## Usage
11352
114- ### Advanced Configuration
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
11557
116- ``` dart
117- final requestModel = ChatRequestModel(
118- model: PerplexityModel.sonar,
119- messages: messages,
120- temperature: 0.7, // Creativity (0.0-2.0)
121- topP: 0.9, // Nucleus sampling
122- searchDomainFilter: ['nature.com'], // Limit sources
123- returnRelatedQuestions: true, // Follow-up suggestions
124- searchRecencyFilter: 'month', // Time filter
125- maxTokens: 1000,
126- );
127- ```
58+ ** Flutter Widget Layer:**
59+ - ` ChatWrapperWidget ` for BLoC state management
60+ - ` PerplexityChatView ` for real-time message display
61+ - ` PerplexityChatInput ` for user interaction handling
12862
12963## Code Explanation
13064
131- ### Architecture
132-
133- ** Two-layer design:**
134- 1 . ** Core (` perplexity_dart ` )** - Pure Dart API client
135- 2 . ** UI (` perplexity_flutter ` )** - Flutter widgets + BLoC state management
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
13671
137- ### Multimodal Processing
72+ ## Architecture
13873
139- Uses flexible message parts for combining text and images:
140-
141- ``` dart
142- final message = ImageMessageModel(
143- role: MessageRole.user,
144- content: [
145- TextPart(text: 'Analyze these images'),
146- ImagePart(url: 'https://example.com/image1.jpg'),
147- ImagePart(url: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgA...'),
148- ],
149- );
150- ```
151-
152- ### Available Models
153-
154- ``` dart
155- PerplexityModel.sonar // 128K tokens - Fast queries
156- PerplexityModel.sonarPro // 200K tokens - Enhanced
157- PerplexityModel.sonarDeepResearch // 128K tokens - Research
158- PerplexityModel.sonarReasoning // 128K tokens - Complex reasoning
159- PerplexityModel.sonarReasoningPro // 128K tokens - Advanced reasoning
160- ```
161-
162- ### Error Handling
163-
164- ``` dart
165- try {
166- final response = await client.sendMessage(requestModel: request);
167- } on PerplexityException catch (e) {
168- print('API Error: ${e.message} (${e.statusCode})');
169- } catch (e) {
170- print('Error: $e');
171- }
172- ```
74+ ** Two-layer design:**
75+ - ** Core (` perplexity_dart ` )** - Pure Dart API client for all platforms
76+ - ** UI (` perplexity_flutter ` )** - Flutter widgets + BLoC state management
17377
78+ Uses flexible MessagePart system for multimodal content combining text and images.
17479## Links
17580
17681** Packages:**
17782- [ perplexity_dart on pub.dev] ( https://pub.dev/packages/perplexity_dart ) | [ GitHub] ( https://github.com/vishnu32510/perplexity_dart )
17883- [ perplexity_flutter on pub.dev] ( https://pub.dev/packages/perplexity_flutter ) | [ GitHub] ( https://github.com/vishnu32510/perplexity_flutter )
17984
180- ** Resources :**
181- - [ Flutter Examples ] ( https://github.com/vishnu32510/perplexity_dart/tree/main/example_flutter_app )
85+ ** Examples :**
86+ - [ Flutter Example App ] ( https://github.com/vishnu32510/perplexity_dart/tree/main/example_flutter_app )
18287- [ Dart Examples] ( https://github.com/vishnu32510/perplexity_dart/tree/main/example )
183- - [ Perplexity API Docs] ( https://docs.perplexity.ai/ )
184-
185- ** Contributing:** Issues and PRs welcome on both [ perplexity_dart] ( https://github.com/vishnu32510/perplexity_dart/issues ) and [ perplexity_flutter] ( https://github.com/vishnu32510/perplexity_flutter/issues ) repositories.
186-
187- ## Limitations
188-
189- - ** API Rate Limits** - Implement rate limiting for production use
190- - ** Image Formats** - Base64, data URI, HTTPS URLs supported; local files need conversion
191- - ** Context Windows** - 128K-200K token limits per model
192- - ** API Key Security** - Store securely; avoid hardcoding in client apps
193- - ** Streaming Dependencies** - Requires WebSocket support on target platforms
194- - ** Flutter Web** - Limited file operations in web environments
19588
196- ** Production Tips :** Implement API key rotation, retry logic, caching strategies, usage monitoring, and proper error boundaries .
89+ ** Contributing :** Issues and PRs welcome on both repositories .
0 commit comments