nashid_verify_sdk 2.6.6 copy "nashid_verify_sdk: ^2.6.6" to clipboard
nashid_verify_sdk: ^2.6.6 copied to clipboard

The nashid_verify_sdk Flutter plugin provides an interface to integrate the Nashid SDK into your application for document scanning and verification purposes.

example/lib/example.dart

/// example/lib/main.dart
/// Complete usage example for Nashid Verify SDK
///
/// This demonstrates all SDK functions in a typical verification workflow.
///
/// **Before running:**
/// 1. Replace "YOUR_SDK_KEY" and "YOUR_SDK_SECRET" with actual credentials
/// 2. Configure your Info.plist (iOS) and AndroidManifest.xml (Android)
/// 3. Run: flutter pub get
library;

import 'dart:developer';

import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:nashid_verify_sdk/nashid_verify_sdk.dart';
import 'dart:async';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Nashid Verify SDK Example',
      theme: ThemeData(primarySwatch: Colors.blue),
      home: const VerificationExampleScreen(),
    );
  }
}

class VerificationExampleScreen extends StatefulWidget {
  const VerificationExampleScreen({super.key});

  @override
  State<VerificationExampleScreen> createState() => _VerificationExampleScreenState();
}

class _VerificationExampleScreenState extends State<VerificationExampleScreen> {
  final _nashidSdk = NashidVerifySdk();
  StreamSubscription<NashidExitEvent>? _eventSubscription;

  String _status = 'Not initialized';
  String? _events;
  String _verificationId = '';
  bool _isInitialized = false;

  @override
  void initState() {
    super.initState();
    _initializeSDK();
  }

  /// Step 1: Initialize the SDK
  Future<void> _initializeSDK() async {
    setState(() => _status = 'Initializing...');

    // Initialize with your credentials
    InitializeResponse result = await _nashidSdk.initialize<InitializeResponse>(
      sdkKey: "YOUR_SDK_KEY", // Replace with actual key
      sdkSecretKey: "YOUR_SDK_SECRET", // Replace with actual secret
      languageId: NashidLanguage.ENGLISH, // ENGLISH or ARABIC
      extraData: {
        "userId": "example_user_123",
        "sessionId": "session_456",
      },
    );

    if (result.result == true) {
      setState(() {
        _isInitialized = true;
        _status = 'SDK Initialized Successfully';
      });
    } else {
      setState(() {
        _status = 'Initialization Failed: ${result.errorMessage}';
      });
    }
  }

  /// Step 2: Listen to SDK exit events (Type-safe enum approach)
  void _setupEventListeners() {
    if (_eventSubscription != null) {
      _eventSubscription?.cancel();
    }

    _eventSubscription = _nashidSdk.onSDKExit.listen((event) {
      if (kDebugMode) {
        print('📱 SDK Event: ${event.displayName}');
      }

      switch (event) {
        case NashidExitEvent.COMPLETED:
          _handleEvents('Completed');
          break;
        case NashidExitEvent.OCR_CANCELLED:
          _handleEvents('OCR Cancelled');
          break;
        case NashidExitEvent.NFC_CANCELLED:
          _handleEvents('NFC Cancelled');
          break;
        case NashidExitEvent.LIVENESS_CANCELLED:
          _handleEvents('Liveness Cancelled');
          break;
        case NashidExitEvent.MALA_CONSENT_DECLINED:
          _handleEvents('Consent Declined');
          break;
        case NashidExitEvent.UNKNOWN:
          debugPrint('Unknown event');
          break;
      }
    });
  }

  /// Step 3: Start verification process
  Future<void> _startVerification(NashidDocumentType documentType) async {
    if (!_isInitialized) {
      setState(() => _status = 'Please initialize SDK first');
      return;
    }

    setState(() => _status = 'Starting verification...');

    /// Setup event listeners before starting verification
    _setupEventListeners();

    final VerificationResponse result = await _nashidSdk.verify<VerificationResponse>(ofType: documentType);

    if (result.result == true) {
      setState(() {
        _verificationId = result.verificationID;
        _status = 'Verification started. ID: $_verificationId';
      });
      _handleVerificationCompleted();
    } else {
      setState(() {
        _status = 'Verification failed: ${result.errorMessage}';
      });
    }
  }

  /// Step 4: Handle verification completion
  Future<void> _handleVerificationCompleted() async {
    if (_verificationId.isEmpty) {
      setState(() => _status = 'No verification ID available');
      return;
    }

    setState(() => _status = 'Fetching verification result...');

    final VerificationResultResponse result = await _nashidSdk.getVerificationResult<VerificationResultResponse>(
      verificationId: _verificationId,
    );

    if (result.result == true) {
      final scanData = result.scanData;
      setState(() {
        _status = 'Verification Complete!\n'
            'Status: ${scanData?.data?.status.title ?? 'Unknown'}\n'
            'Type: ${scanData?.data?.type.title ?? 'Unknown'}';
      });
      if (kDebugMode) {
        log("Whole object:");
        log(scanData.toString());
      }

      // Process the verification data
      _processVerificationData(scanData);
    } else {
      setState(() {
        _status = 'Failed to get result: ${result.errorMessage}';
      });
    }
  }

  /// Process the complete verification data
  void _processVerificationData(ScanData? scanData) {
    if (scanData == null) return;

    // Access various data sections
    final nfcData = scanData.data?.data.nfc;
    final ocrData = scanData.data?.data.scan;
    final livenessData = scanData.data?.data.liveness;
    final metadata = scanData.data?.metaData;
    final artifacts = scanData.data?.artifacts;

    if (kDebugMode) {
      print('🎉 Verification Data:');
      print('NFC: ${nfcData?.toJson().toString()}');
      print('OCR: ${ocrData?.toJson().toString()}');
      print('Liveness: ${livenessData?.toJson().toString()}');
      print('Metadata: ${metadata?.toJson().toString()}');
      print('Artifacts: ${artifacts?.toJson().toString()}');
    }

    /// Cancel event listeners after processing
    _eventSubscription?.cancel();
  }

  /// Handle verification cancellations
  void _handleEvents(String reason) {
    /// add your own logic here to handle the events
    setState(() => _events = reason);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Nashid Verify SDK Example'),
      ),
      body: Padding(
        padding: const EdgeInsets.all(16.0),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.stretch,
          children: [
            // Status Display
            Row(
              children: [
                Expanded(
                  flex: 2,
                  child: Container(
                    padding: const EdgeInsets.all(12),
                    decoration: BoxDecoration(
                      color: Colors.grey[200],
                      borderRadius: BorderRadius.circular(8),
                    ),
                    child: Column(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        Text(
                          _status,
                          style: const TextStyle(fontSize: 14),
                        ),
                        Divider(thickness: 0.5),
                        if (_events != null)
                          Text(
                            "Callback event:$_events",
                            style: const TextStyle(fontSize: 14),
                          ),
                      ],
                    ),
                  ),
                ),
                SizedBox(width: 10),
                Expanded(
                  child: ElevatedButton(
                    onPressed: () {
                      _initializeSDK();
                    },
                    child: Text("Initialize"),
                  ),
                )
              ],
            ),
            const SizedBox(height: 24),

            // Verification Buttons
            const Text(
              'Select Document Type to Verify:',
              style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold),
            ),
            const SizedBox(height: 12),

            _buildVerifyButton('Omani ID', NashidDocumentType.OMANI_ID),
            _buildVerifyButton('International Passport', NashidDocumentType.INTERNATIONAL_PASSPORT),
            _buildVerifyButton('Emirati ID', NashidDocumentType.EMIRATI_ID),
            _buildVerifyButton('Saudi ID', NashidDocumentType.SAUDI_ID),
            _buildVerifyButton('Bahraini ID', NashidDocumentType.BAHRAINI_ID),
            _buildVerifyButton('Qatari ID', NashidDocumentType.QATARI_ID),
            _buildVerifyButton('Kuwaiti ID', NashidDocumentType.KUWAITI_ID),
          ],
        ),
      ),
    );
  }

  Widget _buildVerifyButton(String label, NashidDocumentType documentType) {
    return Padding(
      padding: const EdgeInsets.only(bottom: 8.0),
      child: ElevatedButton(
        onPressed: _isInitialized ? () => _startVerification(documentType) : null,
        child: Text(label),
      ),
    );
  }
}
0
likes
140
points
333
downloads

Publisher

unverified uploader

Weekly Downloads

The nashid_verify_sdk Flutter plugin provides an interface to integrate the Nashid SDK into your application for document scanning and verification purposes.

Homepage

Documentation

API reference

License

unknown (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on nashid_verify_sdk

Packages that implement nashid_verify_sdk