When to use Shenai Sdk
The **Shenai SDK** brings the power of Shen.ai’s artificial‑intelligence services directly into Flutter applications. By wrapping the native iOS and Android libraries, the plugin offers a unified Dart API that lets developers call speech‑to‑text, natural‑language understanding, image analysis, and other AI‑driven features without leaving the Flutter ecosystem. The package abstracts platform‑specific initialization, permission handling, and data streaming, allowing you to focus on the user experience rather than low‑level native code. Whether you are building a voice‑activated assistant, a real‑time translation tool, or an intelligent image‑search feature, Shenai SDK provides the building blocks to embed sophisticated AI capabilities with just a few lines of Dart.
When to use Shenai SDK? Choose this plugin when your project requires on‑device or cloud‑backed AI that is already curated by Shen.ai. The SDK shines in scenarios where you need high‑accuracy speech recognition, language detection, or visual classification that is continuously updated by the provider. Because the plugin follows Flutter’s null‑safety guidelines and respects platform constraints, it integrates cleanly with modern codebases that adopt Provider, Riverpod, or Bloc for state management. It also plays nicely with clean‑architecture or MVVM patterns, as the AI calls are exposed as asynchronous futures or streams that can be injected into repository layers.
In terms of architecture, Shenai SDK sits at the data‑service layer of a typical Flutter app. You would create a thin wrapper class—often called `ShenaiRepository`—that forwards calls to the plugin’s methods such as `startSpeechRecognition()` or `analyzeImage()`. This repository can then be consumed by your domain or presentation layers, keeping the UI free from platform concerns. Because the plugin supports both Android (minSdk 21) and iOS (12+), you can safely target mobile devices while still maintaining a single codebase. The package does not currently support web or desktop, so if you need cross‑platform AI on those targets you will have to fall back to alternative solutions.
Setting up the SDK is straightforward. After adding the dependency with `flutter pub add shenai_sdk`, you must register the native SDK keys in the platform‑specific configuration files (`AndroidManifest.xml` for Android and `Info.plist` for iOS). The plugin also provides a helper method `Shenai.initialize()` that validates the configuration and prepares the native libraries. During development, enable verbose logging to troubleshoot permission issues or network errors. For production, consider disabling debug logs and handling error callbacks gracefully, as AI services may return latency spikes or quota limits that could affect user experience.
Production‑grade usage calls for a few extra cautions. First, respect user privacy by requesting microphone or camera permissions only when needed, and clearly explain why the data is being processed. Second, monitor the SDK’s quota and billing model; many AI services charge per request, so implement throttling or caching where appropriate. Third, test on a range of devices to ensure consistent performance, especially on lower‑end Android phones where CPU and memory constraints can impact real‑time inference. Finally, keep the plugin up to date—new releases often include performance optimizations, security patches, and expanded model support that can directly improve your app’s reliability.
For beginners, a simple use case might be a voice‑to‑text note‑taking app. By calling `Shenai.startSpeechRecognition()` and listening to the resulting stream, you can display transcribed text in real time, store it locally, and optionally send it to a backend for further analysis. Another entry‑level example is an image‑tagging feature where a user selects a photo, the app invokes `Shenai.analyzeImage()`, and the returned tags are shown as clickable chips. Both examples require minimal code, leverage the plugin’s asynchronous API, and demonstrate how AI can enhance everyday Flutter UI components without overwhelming the developer with complex machine‑learning pipelines.
Pros
- simple unified Dart API
- cross‑platform native integration
- null‑safe and actively maintained
- covers speech, language, and vision
Watch outs
- no web or desktop support yet
- documentation could be deeper
- tied to Shen.ai service pricing
Setup notes
1. Add the dependency: `flutter pub add shenai_sdk` 2. Run `flutter pub get` to fetch the package. 3. Android: add your Shen.ai API key to `android/app/src/main/AndroidManifest.xml` inside the `<application>` tag. 4. iOS: add the same key to `ios/Runner/Info.plist`. 5. Call `await Shenai.initialize();` before using any AI features, typically in `main()` or the first screen's `initState`. 6. Ensure you have the required permissions (microphone, camera) declared in the platform files and request them at runtime.
Requires Flutter 3.0 or newer. Supports Android API level 21+ and iOS 12+. No web or desktop support at this time. Works with Dart null‑safety. Ensure your project’s minSdkVersion and deploymentTarget meet the above requirements.
import 'package:flutter/material.dart';
import 'package:shenai_sdk/shenai_sdk.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Shenai.initialize();
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
home: const SpeechScreen(),
);
}
}
class SpeechScreen extends StatefulWidget {
const SpeechScreen({super.key});
@override
State<SpeechScreen> createState() => _SpeechScreenState();
}
class _SpeechScreenState extends State<SpeechScreen> {
String _transcript = '';
StreamSubscription<String>? _sub;
@override
void initState() {
super.initState();
_sub = Shenai.startSpeechRecognition().listen((text) {
setState(() => _transcript = text);
});
}
@override
void dispose() {
_sub?.cancel();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Shenai Speech Demo')),
body: Padding(
padding: const EdgeInsets.all(16.0),
child: Text(_transcript, style: const TextStyle(fontSize: 18)),
),
);
}
}