Skip to main content
Integrate DigiLocker document retrieval into your Flutter app using the native SDK. The SDK provides an embedded interface that works on both iOS and Android.

View on pub.dev

Check out the package on pub.dev for latest version and updates
1

Create a session

Before initializing the SDK, you must create a unique session. Each SDK instance requires its own session to ensure secure and independent interactions.Use the Create Session endpoint to generate this session. This is a server-side API call that uses Sandbox Authentication to validate your credentials.Once created, you’ll receive a session_id, which you’ll need when initializing the SDK on the client side.
2

Install the package

Add the DigiLocker SDK package to your Flutter project.
flutter pub add sandbox_digilocker_sdk
Or add it manually to your pubspec.yaml:
dependencies:
  sandbox_digilocker_sdk: ^1.0.0
Requirements: Flutter SDK ^3.10.1
3

Integrate the SDK

Import the SDK, set your API key, configure options, and launch the DigiLocker flow.

3.1 Basic implementation

import 'package:sandbox_digilocker_sdk/sandbox_digilocker_sdk.dart';

// Set your API key
DigilockerSDK.instance.setAPIKey('key_your_api_key_here');

// Set event listener (optional)
DigilockerSDK.instance.setEventListener(SDKEventListener());

// Launch the SDK
await DigilockerSDK.instance.open(
  context: context,
  options: {
    'session_id': 'a7fac865-61a9-4589-b80c....', // Replace with your session ID from Step 1
    'brand': {
      'name': 'MoneyApp', // Your business or app name
      'logo_url': 'https://i.imgur.com/vMd9Wcu.png', // Publicly accessible URL
    },
    'theme': {
      'mode': 'light', // Options: 'light' or 'dark'
      'seed': '#3D6838', // Primary color for theme customization
    },
  },
);
{
  "session_id": "a7fac865-61a9-4589-b80c....",
  "brand": {
    "name": "MoneyApp",
    "logo_url": "https://i.imgur.com/vMd9Wcu.png"
  },
  "theme": {
    "mode": "light",
    "seed": "#3D6838"
  }
}
session_id
string
required
Unique session ID generated when Create Session API is called.
brand
object
required
Configuration for branding displayed in the DigiLocker interface.
theme
object
required
Appearance configuration for the SDK.
4

Handle SDK events

Set up an event listener to handle SDK events indicating session completion or cancellation.
class SDKEventListener implements EventListener {
  @override
  void onEvent(Map<String, dynamic> event) {
    print('Received event: $event');
    
    final eventType = event['type'];
    
    if (eventType == 'in.co.sandbox.kyc.digilocker_sdk.session.completed') {
      // Documents were fetched successfully
      // Proceed with your application flow
      fetchDocumentsFromBackend(sessionId);
    } else if (eventType == 'in.co.sandbox.kyc.digilocker_sdk.session.closed') {
      // User closed the SDK
      print('User closed the SDK');
    }
  }
}
To programmatically verify the final status of a session, call the Session Status endpoint from your backend.

Event types

The SDK emits the following event types via the EventListener:
Event TypeDescription
in.co.sandbox.kyc.digilocker_sdk.session.completedUser successfully completed the DigiLocker flow and documents were retrieved
in.co.sandbox.kyc.digilocker_sdk.session.closedUser closed the SDK without completing the flow

API reference

DigilockerSDK

The main SDK class that provides a singleton instance. Methods: setAPIKey(String apiKey)
  • Sets the API key required to authenticate requests
  • Parameters: apiKey (String) - The API key string starting with “key_”
  • Throws: Exception if the API key does not start with “key_”
open(BuildContext context, Map options)
  • Opens the SDK UI with the provided configuration
  • Parameters:
    • context (BuildContext) - The BuildContext from which the SDK is accessed
    • options (Map) - Configuration options including session_id, brand, and theme
  • Throws: Exception if API key or required options are not set
setEventListener(EventListener eventListener)
  • Registers an event listener to receive SDK events
  • Parameters: eventListener (EventListener) - The event listener to register

EventListener

Interface for receiving SDK events. Methods: onEvent(Map event)
  • Called when an SDK event occurs
  • Parameters: event (Map) - The event data containing event type and payload

Next steps