DDLens Docs
Flutter mobile SDK

One Flutter API, native recognition.

Use the original iOS framework and native Android scanner through a compact, null-safe Dart interface.

v1.9.0 · StableFlutter 3.24+iOS 17+Android API 26+

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

pubspec.yaml
dependencies:
  dlens_flutter:
    path: ../dlens_flutter
Terminal
flutter pub get

The 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.

ios/Runner/Info.plist
<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/app/build.gradle.kts
android {
    defaultConfig {
        minSdk = 26
    }
}

Initialise

main.dart
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

Dart
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

Dart
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

Dart
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 licences
  • mrzOnly — ICAO TD1, TD2, and TD3 documents
  • all — 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

CapabilityiOSAndroid
Live cameraOriginal DLens scannerCameraX + ML Kit
PDF417iOS SDK pipelinesML Kit; ZXing for still images
MRZ OCRVisionML Kit Latin OCR
MinimumiOS 17API 26

Simulator builds verify integration, but camera qualification must run on physical iOS and Android devices.