platform_text_recognition
On-device OCR for Flutter using platform-native engines:
- iOS: Apple Vision (
VNRecognizeTextRequest) — no ML Kit or third-party iOS OCR dependencies - Android: Google ML Kit Text Recognition
Why this package?
Unlike all-in-one ML Kit plugins, this package avoids shipping ML Kit on iOS. That keeps the iOS build lighter and sidesteps Swift Package Manager compatibility issues with ML Kit pods.
Platform support
| Platform | Engine | Min version |
|---|---|---|
| iOS | Apple Vision | iOS 13+ |
| Android | ML Kit | API 21+ |
Installation
dependencies:
platform_text_recognition: ^0.1.0
Usage
import 'package:platform_text_recognition/platform_text_recognition.dart';
final text = await PlatformTextRecognizer.instance.recognizeText(
'/absolute/path/to/image.jpg',
);
print(text);
Or use the top-level helper:
final text = await recognizeTextFromImage('/absolute/path/to/image.jpg');
Returns an empty string when no text is detected. Throws PlatformException when the file is missing or recognition fails.
Language and script support
Use TextRecognitionScript to pick the OCR model on Android. On iOS, when you omit explicit language hints, the script maps to default Vision language codes.
// Japanese text (Android: ML Kit Japanese; iOS: ja-JP hint)
final japanese = await PlatformTextRecognizer.instance.recognizeText(
imagePath,
script: TextRecognitionScript.japanese,
);
// Chinese text
final chinese = await PlatformTextRecognizer.instance.recognizeText(
imagePath,
script: TextRecognitionScript.chinese,
);
// Devanagari (Hindi, etc.) — Android only
final hindi = await PlatformTextRecognizer.instance.recognizeText(
imagePath,
script: TextRecognitionScript.devanagari,
);
On iOS you can also pass explicit BCP-47 language codes:
final french = await PlatformTextRecognizer.instance.recognizeText(
imagePath,
languages: ['fr-FR', 'en-US'],
);
When languages is omitted on iOS 16+, Vision auto-detects the language for Latin script.
Arabic is supported on iOS via language codes (ML Kit does not offer an Arabic script model on Android):
final arabic = await PlatformTextRecognizer.instance.recognizeText(
imagePath,
languages: ['ar-SA'], // ar-EG, ar-AE, etc.
);
| Script | Android | iOS |
|---|---|---|
latin |
ML Kit Latin | Auto-detect (or explicit languages) |
chinese |
ML Kit Chinese | zh-Hans, zh-Hant |
japanese |
ML Kit Japanese | ja-JP |
korean |
ML Kit Korean | ko-KR |
devanagari |
ML Kit Devanagari | Not supported by Vision |
Example
See the example/ app for a minimal image picker + OCR demo.
cd example
flutter run
App size (Android)
This plugin bundles ML Kit models for all supported scripts (Latin, Chinese, Devanagari, Japanese, Korean). That adds roughly 100 MB+ to your Android APK/AAB even if you only use one script. Latin-only apps pay the same cost today — optional per-script dependencies may be added in a future release.
Limitations
- File paths must point to local image files (
jpg,png, etc.). languagesis ignored on Android; use TextRecognitionScript there.- Devanagari and Arabic OCR are not available on both platforms (Devanagari: Android only; Arabic: iOS only).
- Web, macOS, Windows, and Linux are not supported.
License
MIT — see LICENSE.