Flutter SDK Guide

The official prembly_identity_kyc package for Flutter allows you to launch identity verification, biometric capture, and liveness challenges across iOS, Android, and Web apps using native Dart bindings.


Installation

Add the latest version of the package from your project root:

flutter pub add prembly_identity_kyc

Or add it to your project's pubspec.yaml file manually:

dependencies:
  flutter:
    sdk: flutter
  prembly_identity_kyc: ^0.1.3

Then run the pub command to fetch the dependency:

flutter pub get

Native Platform Permissions Setup

iOS Configuration (ios/Runner/Info.plist)

Open ios/Runner/Info.plist and append the camera and microphone permission keys:

<key>NSCameraUsageDescription</key>
<string>This app requires access to the camera for identity document scanning and biometric liveness verification.</string>
<key>NSMicrophoneUsageDescription</key>
<string>This app requires access to the microphone for liveness checks.</string>

iOS Podfile (ios/Podfile)

The SDK asks for the camera and microphone through permission_handler, which leaves each permission out of the iOS build unless you switch it on. Without this step, iOS refuses camera access without ever showing a prompt.

In ios/Podfile, inside post_install:

post_install do |installer|
  installer.pods_project.targets.each do |target|
    flutter_additional_ios_build_settings(target)
    target.build_configurations.each do |config|
      config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= [
        '$(inherited)',
        'PERMISSION_CAMERA=1',
        'PERMISSION_MICROPHONE=1',
      ]
    end
  end
end

Then run pod install from the ios directory.

iOS Simulator Limitation

The camera hardware module is unavailable on iOS Simulators. Always test identity verification and face liveness flows on a physical iOS device.

Android Configuration (android/app/src/main/AndroidManifest.xml)

Open android/app/src/main/AndroidManifest.xml and add these permissions just above the <application> tag:

<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.INTERNET" />

Web

No extra configuration is required. The browser asks for camera access when the flow starts.


Implementation Example

Import the library and invoke PremblyIdentityKyc.verify() with your IdentityKycOptions:

import 'package:flutter/material.dart';
import 'package:prembly_identity_kyc/prembly_identity_kyc.dart';

class IdentityVerificationScreen extends StatelessWidget {
  const IdentityVerificationScreen({Key? key}) : super(key: key);

  void startVerification(BuildContext context) {
    PremblyIdentityKyc.verify(
      context: context,
      options: IdentityKycOptions(
        widgetKey: 'wk_live_abc123xyz789',
        widgetId: '550e8400-e29b-41d4-a716-446655440000',
        firstName: 'John',
        lastName: 'Doe',
        email: 'john@example.com',
        callback: (response) {
          debugPrint('Prembly Response: $response');
          
          if (response['status'] == 'success') {
            ScaffoldMessenger.of(context).showSnackBar(
              const SnackBar(content: Text('Identity Verified Successfully!')),
            );
          } else {
            ScaffoldMessenger.of(context).showSnackBar(
              const SnackBar(content: Text('Verification Closed or Failed')),
            );
          }
        },
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('Identity Verification')),
      body: Center(
        child: ElevatedButton(
          onPressed: () => startVerification(context),
          child: const Text('Verify Identity'),
        ),
      ),
    );
  }
}

IdentityKycOptions Parameter Reference

ParameterTypeRequiredDescription
widgetKeyStringYesYour public SDK key from the Prembly dashboard.
widgetIdStringYesThe verification workflow configuration ID created in your dashboard.
firstNameStringYesThe user's first name.
lastNameStringYesThe user's last name.
emailStringYesThe user's email address.
phoneStringOptionalThe user's phone number.
metadataMap<String, dynamic>OptionalCustom key-value pairs returned in callbacks, the session lookup, and webhooks.
collectDeviceDataboolOptionalDefaults to true. Reads the phone's own device ID and details and passes them to the widget, so device checks see the real device. No permission prompt is shown and location is never read. Set to false to use only what the web page can see. Mobile only.
callbackvoid Function(Map<String, dynamic>)OptionalReceives a Map with a status key. See Callback statuses.

Callback statuses

statusWhenOther keys
successVerification finished. The flow closes.data: the session payload.
closedThe user closed the flow.—
errorThe widget reported an error. The flow closes.message
error_display_closedThe SDK showed an error screen (for example, camera access denied) and the user dismissed it.—

Any other event the widget reports is passed to callback as status with its data, and the flow stays open. Don't treat an unrecognised status as the end of the session.

Don't update your records from callback alone. Use webhooks as the source of truth.

To skip the ID screen with a known BVN or NIN, use PremblyWorkflow instead.


Run a Workflow (PremblyWorkflow)

PremblyWorkflow.start() runs one of your compliance workflows in the app. It uses your workflow ID and publishable key instead of a widget key and widget ID. Requires 0.1.3 or later.

import 'package:prembly_identity_kyc/prembly_identity_kyc.dart';

void startOnboarding(BuildContext context) {
  PremblyWorkflow.start(
    context: context,
    options: WorkflowOptions(
      publishableKey: 'test_pk_...',
      workflowId: 'wf_123',
      customer: const WorkflowCustomer(
        firstName: 'John',
        lastName: 'Doe',
        email: 'john@example.com',
      ),
      metadata: {'user_id': '123456'},
      // Optional: a BVN or NIN you already have, so they skip the ID screen
      prefill: const WorkflowPrefill(bvn: '22212345678'),
      callback: (result) {
        debugPrint('Workflow ended: ${result.status}');
      },
    ),
  );
}

iOS and Android only. On the web, callback receives failed with errorCode not_available. The camera and microphone are asked for only when a step needs them.

WorkflowOptions Parameter Reference

ParameterTypeRequiredDescription
publishableKeyStringYesYour publishable key: live_pk_... or test_pk_.... A secret key is refused.
workflowIdStringYesThe workflow to run (wf_...), from your workflows list in the dashboard.
customerWorkflowCustomerYesThe person going through the workflow: firstName, lastName, email (required), phone, reference (your own reference for them).
callbackvoid Function(WorkflowResult)YesCalled once when the flow ends. See Workflow results.
prefillWorkflowPrefillOptionalA BVN or NIN you already have. The customer skips the ID screen. See Prefill an ID number.
metadataMap<String, dynamic>OptionalYour own data, stored with the run.
redirectUrlStringOptionalWhere to send the customer when the workflow finishes.
collectDeviceDataboolOptionalDefaults to true. Passes the phone's device ID and details to the workflow, so its device checks see the real device. No permission prompt is shown.
onEventvoid Function(WorkflowEvent)OptionalCalled for every event the workflow reports, with type, sessionId and nodeId. Contains no personal data.

Workflow results

callback receives a WorkflowResult with status and, once a session exists, sessionId:

statusMeaning
completedThe workflow finished.
failedThe workflow ended in failure. If it could not start at all, sessionId is empty and errorCode and errorMessage say why: invalid_key, invalid_request, unauthorised, not_found, rate_limited, server_error, network_error, timeout or not_available.
manual_reviewThe workflow ended and is waiting for a reviewer.
expiredThe session expired before the customer finished.
cancelledThe customer closed the flow before it ended. lastEvent is the last event seen; processing means they finished their steps and the checks continue in the background.

As with the widget, use webhooks for the final outcome.


Troubleshooting (Flutter)

  • Build Failure on Android: The plugin builds against compileSdk 36 and needs minSdk 24 or higher. Check both in android/app/build.gradle.
  • Camera Denied on iOS Without a Prompt: The PERMISSION_CAMERA=1 and PERMISSION_MICROPHONE=1 flags are missing from ios/Podfile. See iOS Podfile, then run pod install again.
  • Camera Crash on iOS: Confirm that NSCameraUsageDescription is present in Info.plist. iOS terminates applications immediately if camera access is requested without a description string.