startVerificationFlow method

Future<void> startVerificationFlow({
  1. required BuildContext context,
  2. required VerificationType verificationType,
  3. File? documentFile,
  4. String? bearerToken,
  5. dynamic onVerificationComplete(
    1. VerificationResponse
    )?,
  6. dynamic onError(
    1. String
    )?,
})

Start the verification flow with app-controlled verification type The app decides whether to show complete verification or face-only verification

Implementation

Future<void> startVerificationFlow({
  required BuildContext context,
  required VerificationType verificationType,
  File? documentFile, // Required when verificationType is facematch
  String? bearerToken,
  Function(VerificationResponse)? onVerificationComplete,
  Function(String)? onError,
}) async {
  // Validate that documentFile is provided when verification type is facematch
  if (verificationType == VerificationType.facematch && documentFile == null) {
    throw ArgumentError('documentFile is required when verificationType is facematch');
  }

  // Initialize plugin with bearer token if provided
  initialize(bearerToken: bearerToken);

  // Check for pending manual verification
  final pendingSession = await getPendingSession();
  if (pendingSession != null) {
    final shouldStartNew = await showPendingVerificationDialog(context);
    if (shouldStartNew == null) {
      // User dismissed dialog, don't proceed
      return;
    } else if (shouldStartNew == false) {
      // User wants to check status, handle in main app
      if (pendingSession['session_id'] != null) {
        onVerificationComplete?.call(VerificationResponse(
          status: 'check_pending_status',
          sessionId: pendingSession['session_id'],
          message: 'Check pending verification status',
        ));
      }
      return;
    } else {
      // User wants to start new verification, clear pending session
      await clearPendingSession();
    }
  }

  // Show the verification flow with the specified verification type
  await Navigator.of(context).push(
    MaterialPageRoute(
      builder: (context) => SotaIdVerificationFlow(
        verificationType: verificationType,
        documentFile: documentFile,
        bearerToken: bearerToken,
        onVerificationComplete: (response) async {
          // Store session if manual verification is required
          if (response.status == 'requires_manual_verification') {
            await storePendingSession(response);
          }
          onVerificationComplete?.call(response);
        },
        onError: onError,
      ),
    ),
  );
}