One Flutter API, native recognition.
Use the original iOS framework and native Android scanner through a compact, null-safe Dart interface.
Overview
The plugin does not reimplement recognition in Dart. iOS calls the bundled DLens XCFramework, while Android calls the Kotlin/CameraX implementation. Configuration and result models remain consistent.
Requirements
- Flutter 3.24+ and Dart 3.5+
- iOS 17+, Xcode 15+, and Swift 5.9
- Android API 26+ and Java 17
- Credentials issued for each target identifier
This plugin targets Flutter on iOS and Android. Use the separate Web SDK for Flutter Web.
Installation
dependencies:
dlens_flutter:
path: ../dlens_flutterflutter pub getThe distribution already contains the iOS XCFramework and Android implementation.
Native setup
iOS
Set the deployment target to iOS 17 and add the camera purpose string.
<key>NSCameraUsageDescription</key>
<string>We use the camera to scan identity documents.</string>Android
Set the app minimum SDK to 26. The plugin contributes camera permission and the scanner activity.
android {
defaultConfig {
minSdk = 26
}
}Initialise
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
await DLens.initialize(
apiKey: const String.fromEnvironment('DLENS_API_KEY'),
secret: const String.fromEnvironment('DLENS_SECRET'),
configuration: const DLensConfiguration(
scanMode: DLensScanMode.all,
timeoutSeconds: 60,
),
);
runApp(const App());
}Present the scanner
try {
final result = await DLens.presentScanner(
mode: DLensScanMode.all,
);
if (result == null) return; // User cancelled.
debugPrint(result.fullName);
} on PlatformException catch (error) {
debugPrint(error.code);
debugPrint(error.message);
}Scan an existing image
final bytes = await File(imagePath).readAsBytes();
final result = await DLens.scanImage(
bytes,
mode: DLensScanMode.all,
);Use JPEG, PNG, or another image format supported by the target platform.
Parse a payload
final result = await DLens.parse(rawAamvaOrMrzText);Configuration
DLensConfiguration supports scan mode, timeout, automatic zoom, zoom bounds, rescan zoom offset, scanner control visibility, tip and instruction visibility, mode badge visibility, and dismissal behavior.
barcodeOnly— AAMVA PDF417 driver licencesmrzOnly— ICAO TD1, TD2, and TD3 documentsall— both recognition paths
Result model
DLensScanResult requires first name, last name, licence/document number, and raw payload. Optional values cover other names, DateTime dates, licence details, address, country, gender, eye colour, and height. fullName joins present name components.
Errors
Native failures arrive as PlatformException. Handle notInitialized, invalidAPIKey, invalidSecret, licenseExpired, licenseKeyMismatch, cameraPermissionDenied, scanningFailed, and timeout. Retain both code and message in logs.
Platform behavior
| Capability | iOS | Android |
|---|---|---|
| Live camera | Original DLens scanner | CameraX + ML Kit |
| PDF417 | iOS SDK pipelines | ML Kit; ZXing for still images |
| MRZ OCR | Vision | ML Kit Latin OCR |
| Minimum | iOS 17 | API 26 |
Simulator builds verify integration, but camera qualification must run on physical iOS and Android devices.